题解 | #统计字符# 逻辑判断+ASCII理解
统计字符
https://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5
#include <iostream> using namespace std; int main() { string st; getline(cin,st); int n = st.size(), letters = 0, blanks = 0, numbers = 0, others = 0; for(int i=0; i<n; i++){ if((st[i] >= 'a' && st[i] <= 'z') || (st[i] >= 'A' && st[i] <= 'Z')){ letters++; } else if(st[i] == ' '){ blanks++; } else if((st[i] >= '0') && (st[i] <= '9')){ numbers++; } else{ others++; } } cout << letters << endl; cout << blanks << endl; cout << numbers << endl; cout << others << endl; return 0; } // 64 位输出请用 printf("%lld")