提交时间:2024-11-02 08:26:36
运行 ID: 55016
#include<bits/stdc++.h> using namespace std; int a[26]; char c[26], ch= 'A'; int main() { for (int i = 0; i < 26; i++) { c[i] = ch; ch++; } string s; getline(cin,s); for (int i = 0; s[i] != '\0'; i++) { if(s[i] >= 'A' && s[i] <= 'Z') { a[s[i] - 'A']++; }else if(s[i] >= 'a' && s[i] <= 'z') { a[s[i] - 'a']++; } } for(int i = 0; i < 25; i++) { for (int j = 0; j < 25; j++) { if(a[j] < a[j+1]) { swap(a[j], a[j+1]); swap(c[j], c[j+1]); } } } for (int i = 0; i < 26; i++) { cout << i + 1 <<" "<<c[i] <<": " <<a[i] << endl; } return 0; }