#include <iostream>
#include <vector>
using namespace std;
int main() {
string s;
getline(cin, s);
vector<int> count(126 - 32 + 1, 0);
for (char c : s) {
count[c - ' ']++;
}
// 统计不同情况
int digit = 0;
for (int i = '0' - ' '; i <= '9' - ' '; i++) {
digit += count[i];
}
int space = count[0];
int alpha = 0;
for (int i = 'A' - ' '; i <= 'Z' - ' '; i++) {
alpha += count[i];
}
for (int i = 'a' - ' '; i <= 'z' - ' '; i++) {
alpha += count[i];
}
int other = 0;
for(int i = ' ' - ' '; i <= '~'- ' '; i++){
other += count[i];
}
other = other - space - alpha - digit;
// 输出
cout << alpha << endl;
cout << space << endl;
cout << digit << endl;
cout << other << endl;
}
// 64 位输出请用 printf("%lld")
- 本题是统计由小写字母构成的字符串的拓展,拓展成统计由常见字符构成的字符串,并且输出统计得到的数量。
- 另一种变体是统计结束后去掉出现次数最多或最少的部分,然后按原来的顺序输出。
- 涉及统计字符串的部分,往往用ASCII码的差值,因为原值并不容易记住,但是顺序容易记住——数字总是0开头,字母总是A或a开头。