程序說明
首先輸入四行數(shù)據(jù),對每行數(shù)據(jù)進(jìn)行處理,將出現(xiàn)的字母保存在數(shù)組中,注意j從0循環(huán)到數(shù)組長度停止。用變量max記錄出現(xiàn)的最大值,逐行輸出。
代碼如下:
#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;
}