链接http://acm.swust.edu.cn/problem/0039/
#include <stdio.h> #include <string.h> int main() { char str[255]; int countnum=0,countletter=0,countchar=0,count=0; fgets(str,sizeof(str),stdin); /* fgets的多组输入形式如下 while(fgets(str,sizeof(str),stdin)!=NULL) { } */ for(int i=0;i<strlen(str)-1;i++) { if(str[i]>='a'&&str[i]<='z'||str[i]>='A'&&str[i]<='Z') { countletter++; } else { if(str[i]>='0'&&str[i]<='9') { countnum++; } else { if(str[i]==' ') { count++; } else { countchar++; } } } } printf("%d %d %d %d\n",countletter,countnum,count,countchar); return 0; }