解题思路:
注意事项:
有个一样的题,要用函数
参考代码:
#include <iostream> #include <string> using namespace std; int main() { string s; int letter = 0, num = 0, space = 0, ch = 0; getline( cin, s ); for ( int i = 0; i < s.size(); i++ ) { if ( s[i] >= 'a' && s[i] <= 'z' || s[i] >= 'A' && s[i] <= 'Z' ) letter++; else if ( s[i] >= '0' && s[i] <= '9' ) num++; else if ( s[i] == ' ' ) space++; else ch++; } cout << letter << ' ' << num << ' ' << space << ' ' << ch; return 0; }
0.0分
1 人评分