题解 | #统计字符#
统计字符
https://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5
// HJ40 统计字符.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 #include<iostream> #include<bits/stdc++.h> using namespace std; int main() { string s; while (getline(cin, s)) { int a = 0, b = 0, c = 0, d = 0; for (int i = 0; i < s.size(); i++) { if (isalpha(s[i])) { a++; } else if (isdigit(s[i])) { c++; } else if (s[i] == ' ') { b++; } else d++; } cout << a << endl << b << endl << c << endl << d << endl; } return 0; }