程序说明
首先输入四行数据,对每行数据进行处理,将出现的字母保存在数组中,注意j从0循环到数组长度停止。用变量max记录出现的最大值,逐行输出。
代码如下:
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
int b[26];
int main() {
int max = 0;
string a;
for(int i = 0; i < 4; i++) {
getline(cin, a);
for(int j = 0; j < a.size(); j++) {
if(a[j] >= 'A' && a[j] <= 'Z')
b[a[j] - 65]++;
}
}
for(int i = 0; i < 26; i++) {
if(b[i] > max)
max = b[i];
}
for(int i = max; i > 0; i--) {
for(int j = 0; j < 26; j++) {
if(b[j] >= i)
cout<<"* ";
else
cout<<" ";
}
cout<<endl;
}
for(int i = 0; i < 26; i++)
printf("%c ", 'A' + i);
return 0;
}