题解 | #字母统计#
字母统计
https://www.nowcoder.com/practice/de7bf0945c1c4bd1aa9d49573b831f3c
#include<iostream>
#include<string.h>
#include<bits/stdc++.h>
using namespace std;
int main() {
string str;
int cnt[26];
while (getline(cin, str)) {
memset(cnt, 0, sizeof(cnt));
for (int i = 0; i < str.length(); i++) {
if (str[i] >= 'A' && str[i] <= 'Z') {
cnt[str[i] - 'A']++;
}
}
for (int i = 0; i < 26; i++) {
cout << char('A' + i) << ':' << cnt[i] << endl;
}
}
}

查看4道真题和解析

