题解 | #统计字符#
统计字符
https://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5
#include <stdio.h> int checkAlp(char ch) { if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) return 1; return 0; } int checkNum(char ch) { if(ch >= '0' && ch <= '9') return 1; return 0; } int main() { char ch; int alp = 0, n_ = 0, num = 0, oth = 0; while(EOF != (ch = getchar())) { if(checkAlp(ch)) alp++; else if(checkNum(ch)) num++; else if(ch == ' ') n_++; else if(ch != '\n') oth++; } printf("%d\n%d\n%d\n%d",alp,n_,num,oth); return 0; }