解题思路:思路1:利用<ctype.h>库中的函数,判断字符的ascii码是否为字母(isalpha),数字(isdigit),空格或其他;
思路2:直接利用每个字符是属于字母,数字,空格的范围来判断;
注意事项:
参考代码:
#include<stdio.h> #include<ctype.h> #define Max 200 int main(void) { int alpha=0, digit=0, kong=0, other=0, c = 0; while((c=getchar())!='\n'){ if(isalpha(c)){ alpha++; }else if(isdigit(c)){ digit++; }else if(c==' '){ kong++; }else{ other++; } } printf("%d %d %d %d\n", alpha, digit, kong, other); return 0; }
0.0分
0 人评分
三角形 (C语言代码)浏览:914 |
A+B for Input-Output Practice (VII) (C语言代码)浏览:528 |
星期判断机 (C语言代码)浏览:859 |
数字游戏 (C++代码)浏览:1185 |
A+B for Input-Output Practice (IV) (C语言代码)浏览:471 |
汽水瓶 (C语言代码)浏览:536 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:462 |
汪汪与打针 (C++代码)浏览:1370 |
Manchester-蛇行矩阵,不需要数组,四个变量,解决问题浏览:5991 |
WU-C语言程序设计教程(第三版)课后习题6.7 (C语言代码)浏览:884 |