解题思路:
分四个变量统计就行
注意事项:
为什么回车不算字符
为什么回车不算字符
为什么回车不算字符
参考代码:
#include <stdio.h> int main() { char ch; int letter = 0; int number = 0; int space = 0; int other = 0; while (scanf("%c", &ch)!=EOF && ch != '\n') { if (ch == ' ') space++; else if (ch <= '9' && ch >= '0') number++; else if ((ch <= 'z' && ch >= 'a') || (ch <= 'Z' && ch >= 'A')) letter++; else other++; } printf("%d %d %d %d\n", letter, number, space, other); return 0; }
0.0分
7 人评分
C语言程序设计教程(第三版)课后习题8.4 (C++代码)浏览:569 |
C二级辅导-公约公倍 (C语言代码)浏览:2093 |
2006年春浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:669 |
C语言训练-排序问题<1> (C++代码)浏览:576 |
字符串对比 (C语言代码)浏览:1329 |
A+B for Input-Output Practice (IV) (C语言代码)浏览:436 |
C语言程序设计教程(第三版)课后习题6.4 (C语言代码)浏览:1006 |
模拟计算器 (C++代码)浏览:758 |
2^k进制数 (C语言描述,蓝桥杯)浏览:1386 |
局部变量作函数返回值的问题浏览:948 |
ET 2019-03-29 15:58:02 |
C++兼容C