解题思路:
分四个变量统计就行
注意事项:
为什么回车不算字符
为什么回车不算字符
为什么回车不算字符
参考代码:
#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语言训练-计算1977!* (C++代码)浏览:847 |
C语言程序设计教程(第三版)课后习题8.9 (Java代码)浏览:1325 |
WU-拆分位数 (C++代码)浏览:779 |
printf基础练习2 (C语言代码)浏览:644 |
三角形 (C++代码)递归(存在大量重复计算,容易出现时间超限)浏览:774 |
C语言程序设计教程(第三版)课后习题6.6 (C语言代码)浏览:349 |
1014题解浏览:484 |
最好的,浏览:563 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:518 |
C二级辅导-分段函数 (C语言代码)浏览:738 |
ET 2019-03-29 15:58:02 |
C++兼容C