解题思路:
分四个变量统计就行
注意事项:
为什么回车不算字符
为什么回车不算字符
为什么回车不算字符
参考代码:
#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语言训练-求矩阵的两对角线上的元素之和 (C语言代码)浏览:738 |
母牛的故事 (C语言代码)浏览:766 |
C语言程序设计教程(第三版)课后习题9.10 (C语言代码)浏览:617 |
C语言程序设计教程(第三版)课后习题10.4 (C语言代码)浏览:689 |
最小公倍数 (C语言代码)浏览:878 |
Pascal三角 (C语言代码)浏览:1220 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:615 |
WU-蓝桥杯算法提高VIP-交换Easy (C++代码)浏览:1151 |
校门外的树 (C语言代码)浏览:723 |
核桃的数量 (C语言代码)浏览:699 |
ET 2019-03-29 15:58:02 |
C++兼容C