Run ID 作者 问题 语言 测评结果 时间 内存 代码长度 提交时间
35035 jaypei 字母频率统计 C++ 通过 1 MS 248 KB 779 2023-12-25 20:01:45

Tests(1/1):


#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; }


测评信息: