Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 17233 | Accepted: 8341 |
Description
Input
Output
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
Source
题目大意:
输入四行大写字母的文本,统计每个字母出现的频率。用垂直柱状图显示。
#include <stdio.h> #include <iostream> #include <string> using namespace std; int main() { //freopen("r.txt","w",stdout); string a,a1,a2,a3,a4; int i,c; int max; int sum[26]={0}; getline(cin,a1); getline(cin,a2); getline(cin,a3); getline(cin,a4); a=a1+a2+a3+a4; c=a.length(); for(i=0;i<c;i++) { ++sum[a[i]-'A']; } max = sum[0]; for(i=0;i<26;i++) { if(sum[i]>max) max=sum[i]; } ///////////////////////////////////// int num; for(;max>0;max--) { for(i=25;i>=0;i--) { if(sum[i]>=max) { num=i; break; } } for(i= 0;i<26; i++) { if(sum[i]>= max) { if(i==25) { cout<<"*"; break; } if(i==num) { cout<<"*"; break; } else { cout<<'*'<<" "; } } else { if(i==25) { cout<<" "; break; } else { cout<<" "<<" "; } } } cout<<endl; } for(i= 0; i< 26; i++) { if(i==25) cout<<char('A'+i); else cout<<char('A'+i)<<" "; } cout<<endl; return 0; } /* THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG. THIS IS AN EXAMPLE TO TEST FOR YOUR HISTOGRAM PROGRAM. HELLO! */