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
AC代码:
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int main() { int maxn=-1; string s; int cnt[30]; memset(cnt,0,sizeof(cnt)); for(int i=0; i<4; i++) { getline(cin,s); for(int j=0; j<s.length(); j++) if(isupper(s[j])) cnt[s[j]-'A']++; } for(int i=0; i<26; i++) if(cnt[i]>maxn) maxn=cnt[i]; for(int i=0; i<maxn; i++) { for(int j=0; j<26; j++) if(cnt[j]>=maxn-i) printf("* "); else printf(" "); puts(""); } for(int i=0; i<26; i++) printf("%c ",'A'+i); puts(""); return 0; } //string s的输入用getline(cin,s),长度为s.length(),并且此时的getline(cin,s)可以用gets(s)代替 //char s的输入用gets(s),长度为strlen(s)
运行结果:
学习心得:这个题挺有趣的