解题思路:
分四个变量统计就行
注意事项:
为什么回车不算字符
为什么回车不算字符
为什么回车不算字符
参考代码:
#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 人评分
简单的a+b (C++语言代码)浏览:850 |
数组输出 (C语言代码)错误???浏览:555 |
A+B for Input-Output Practice (III) (C语言代码)浏览:569 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:500 |
C语言程序设计教程(第三版)课后习题11.8 (C语言代码)浏览:867 |
C语言程序设计教程(第三版)课后习题8.7 (C语言代码)浏览:593 |
简单的a+b (C语言代码)浏览:568 |
C语言程序设计教程(第三版)课后习题10.7 (C语言代码)浏览:653 |
简单的事情 (C语言代码)浏览:633 |
字符逆序 (C语言代码)浏览:504 |
ET 2019-03-29 15:58:02 |
C++兼容C