fork download
  1. #include<iostream>
  2. #include <string>
  3. #include <cctype>
  4. using namespace std;
  5. int main()
  6. {
  7. string line;
  8. cout<<"please enter a line"<<endl;
  9. getline(cin,line);
  10. string::size_type nLetter=0,nDigit=0,nOthers=0;
  11. for(auto c:line)
  12. {
  13. if(isalpha(c))
  14. ++nLetter;
  15. if(isdigit(c))
  16. ++nDigit;
  17. else
  18. ++nOthers;
  19. }
  20. cout<<"字母有"<<nLetter<<endl;
  21. cout<<"数字有"<<nDigit<<endl;
  22. cout<<"其他字符有"<<nOthers<<endl;
  23. return 0;
  24. }
Success #stdin #stdout 0s 15240KB
stdin
abcd123ab
stdout
please enter a line
字母有6
数字有3
其他字符有6