解题思路:
注意事项:
参考代码:
#include<iostream> #include<cstdio> #include<string> #include<cmath> using namespace std; int main() { string s; getline(cin, s); int words = 0, num = 0, space = 0, other = 0; for (int i = 0; i < s.length(); i++) { if (s[i] >= 'A'&&s[i] <= 'Z' || s[i] >= 'a'&&s[i] <= 'z') { words++; } else if (s[i] >= '0' && s[i] <= '9') { num++; } else if (s[i] ==' ') { space++; } else { other++; } } cout << words << " " << num << " " << space << " " << other << endl; getchar(); getchar(); return 0; }
0.0分
0 人评分
C语言考试练习题_保留字母 (C语言代码)浏览:581 |
C语言程序设计教程(第三版)课后习题8.7 (C语言代码)浏览:466 |
十->二进制转换 (C语言代码)浏览:1406 |
倒杨辉三角形 (C语言代码)浏览:3906 |
C语言程序设计教程(第三版)课后习题3.7 (C++代码)浏览:998 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:640 |
高精度加法 (C++代码)(大数加法)浏览:934 |
C语言考试练习题_排列 (C语言代码)浏览:1326 |
C语言训练-求1+2!+3!+...+N!的和 (C语言代码)浏览:789 |
IP判断 (C语言代码)浏览:763 |
时玥41 2019-04-01 17:55:16 |
获取字符串的长度