题解 | #统计字符#
统计字符
https://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5
#include <iostream> #include <string> using namespace std; int main() { string inp; getline(cin, inp); int N = inp.size(); int numC = 0; int space = 0; int number = 0; int other = 0; for (int i = 0; i < N; i++) { if ((inp[i] >= 'A' && inp[i] <= 'Z') || (inp[i] >= 'a' && inp[i] <= 'z')) { numC++; } else if (inp[i] == ' ') { space++; } else if (inp[i] >= '0' && inp[i] <= '9') { number++; } else other++; } cout << numC << endl << space << endl << number << endl << other; } // 64 位输出请用 printf("%lld")
没什么好说的
#华为#华为OD机测试题 文章被收录于专栏
个人练习专栏