统计英文字母、空格、数字和其他字符的个数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include <stdio.h> int main(int argc, char *argv[]) { int c; int nchar=0; int nwhite=0; int ndigit=0; int nothers=0; while((c=getchar())!='n') { if ((c>='a' &&c<='z') || (c>='A' &&c<='Z')) nchar++; else if (c==' ' || c=='t') nwhite++; else if (c>='0' && c<='9') ndigit++; else nothers++; } printf("%d %d %d %d", nchar,ndigit,nwhite,nothers); return 0; } |