fork download
  1. #include <iostream>
  2. #include <cctype>
  3. using namespace std;
  4.  
  5. int main() {
  6. string s = "Hello, World! 2025";
  7. int letters = 0, digits = 0, spaces = 0, others = 0;
  8.  
  9. for (char c : s) {
  10. if (isalpha(c)) letters++;
  11. else if (isdigit(c)) digits++;
  12. else if (isspace(c)) spaces++;
  13. else others++;
  14. }
  15.  
  16. cout << "字母: " << letters << endl;
  17. cout << "数字: " << digits << endl;
  18. cout << "空格: " << spaces << endl;
  19. cout << "其他: " << others << endl;
  20. return 0;
  21. }
Success #stdin #stdout 0.01s 5312KB
stdin
Standard input is empty
stdout
字母: 10
数字: 4
空格: 2
其他: 2