Run ID:118138
提交时间:2025-04-24 18:57:42
#include <iostream> #include <cctype> // 用于字符分类函数 using namespace std; void countCharacters(const string &str, int &letters, int &digits, int &spaces, int &others) { letters = digits = spaces = others = 0; for (char c : str) { if (isalpha(c)) { // 判断是否为字母 letters++; } else if (isdigit(c)) { // 判断是否为数字 digits++; } else if (isspace(c)) { // 判断是否为空白字符(包括空格、制表符等) spaces++; } else { others++; } } } int main() { string input; getline(cin, input); // 读取可能包含空格的整行输入 int letters, digits, spaces, others; countCharacters(input, letters, digits, spaces, others); cout << letters << " " << digits << " " << spaces << " " << others << endl; return 0; }