1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| #include<iostream> using namespace std; int main(){
int n; cin >> n;
int count1[26] = { 0 };
for (int k = 0; k <= n; k++){ char buffer[100]; cin.getline(buffer, 100, '\n'); for (int i = 0; buffer[i] != '\0'; i++){ if (buffer[i] >= 'a' && buffer[i] <= 'z') count1[buffer[i] - 'a']++; if (buffer[i] >= 'A' && buffer[i] <= 'Z') count1[buffer[i] - 'A']++; } }
int count2[26]; int count3 = 0;
for (int i = 0; i < 26; i++){ if (count1[i] != 0){ count2[count3] = i; count3++; } }
if (!count3) cout << "字符串中无字母。"; else{ for (int i = 0; i < count3 - 1; i++) cout << char('a' + count2[i]) << ":" << count1[count2[i]] << endl; cout << char('a' + count2[count3 - 1]) << ":" << count1[count2[count3 - 1]]; }
return 0; }
|