poj 2136 Vertical Histogram

it2024-04-12  9

Vertical Histogram Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 13678 Accepted: 6569

Description

Write a program to read four lines of upper case (i.e., all CAPITAL LETTERS) text input (no more than 72 characters per line) from the input file and print a vertical histogram that shows how many times each letter (but not blanks, digits, or punctuation) appears in the all-upper-case input. Format your output exactly as shown.

Input

* Lines 1..4: Four lines of upper case text, no more than 72 characters per line.

Output

* Lines 1..??: Several lines with asterisks and spaces followed by one line with the upper-case alphabet separated by spaces. Do not print unneeded blanks at the end of any line. Do not print any leading blank lines.

Sample Input

THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG. THIS IS AN EXAMPLE TO TEST FOR YOUR HISTOGRAM PROGRAM. HELLO!

Sample Output

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * A B C D E F G H I J K L M N O P Q R S T U V W X Y Z #include<iostream>#include<cstring>using namespace std;void outPut(int *times){int i,j;int maxtimes = times[0];for(i=0; i<26; i++)if(times[i] > maxtimes) maxtimes = times[i];for(i=maxtimes; i>=1; i--) {for(j=0; j<26; j++) {if(times[j] >= i) cout<<"* ";else cout<<""; } cout<<endl; }for(i='A'; i<='Z'; i++) cout<<(char)i<<""; cout<<endl;}int main(){char output[26][72*4+2];char input[73];int sum[26];int i,j;int n=4;int max;for(i=0;i<26;i++) { output[i][0]='A'+i; sum[i]=0; }for(i=0;i<26;i++) {for(j=1;j<72*4+2;j++) output[i][j]='\0'; }while(n--) { gets(input);for(j=0;input[j]!='\0';j++) {if(input[j]>='A' && input[j]<='Z') { sum[input[j]-'A']++; } }for(i=0;i<26;i++) {for(j=1;j<=sum[i];j++) output[i][j]='*'; } }/* max=sum[0]; for(i=0;i<26;i++) { if(max<sum[i]) max=sum[i]; } for(j=max;j>=0;j--) { for(i=0;i<26;i++) { if(i<25) cout<<output[i][j]<<" "; else cout<<output[i][j]; } cout<<endl; }*/ outPut(sum);return 0;}

转载于:https://www.cnblogs.com/w0w0/archive/2011/11/21/2258199.html

相关资源:数据结构—成绩单生成器
最新回复(0)