提交时间:2024-01-30 18:10:11
运行 ID: 39098
#include<bits/stdc++.h> using namespace std; int cnt[26]; int main() { string n; getline(cin, n); int len = n.size(); for (int i = 0; i < len; i++) { if(n[i] >= 'a' && n[i] <= 'z') { n[i] = n[i] - 32; int x = n[i] - 'A'; cnt[x]++; }else if(n[i] >= 'A' && n[i] <= 'Z') { int x = n[i] - 'A'; cnt[x]++; } } char ch[26], c = 'A'; for (int i = 0; i < 26; i++) { ch[i] = c; c++; } for (int tang = 1; tang < 26; tang++) { for (int wei = 0; wei < 25 ; wei++) { if(cnt[wei] < cnt[wei + 1]) { swap(cnt[wei], cnt[wei + 1]); swap(ch[wei], ch[wei + 1]); } } } for (int i = 0; i < 26; i++) { cout << i + 1 <<" " <<ch[i] <<": " << cnt[i] << endl; } return 0; }