70,037
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char c;
int blank, digit, letter, other;
int ri, repeat;
scanf("%d", &repeat);
getchar();
for(ri = 1; ri<=repeat; ri++)
{
blank=0;
digit=0;
letter=0;
other=0;
while(( c = getchar() ) && c!='\n')
{
if(c==' ')
blank++;
else if(c>='0'&&c<='9')
digit++;
else if(( c>='a'&&c<='z' )|| ( c>='A'&&c<='Z' ) )
letter++;
else
other++;
}
printf("letter = %d, blank = %d, digit = %d, other = %d\n", letter, blank, digit, other);
}
return 0;
}
//不要用c=getchar();
//直接用getchar来吸收掉回车 或者用fflush(stdin);来代替getchar