题解 | #统计字符#
统计字符
http://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5
#include <string.h>
int main()
{
char str[1002];
while( fgets(str, sizeof(str), stdin))
{
int a=0,b=0,c=0,d=-1;
for(int i=0;i<strlen(str);i++)
{
if(str[i]==' ')
b++;
else if(str[i]<='9'&&str[i]>='0')
c++;
else if((str[i]<='z'&&str[i]>='a')||(str[i]<='Z'&&str[i]>='A'))
a++;
else
d++;
}
printf("%d\n%d\n%d\n%d\n",a,b,c,d);
memset(str, 0, sizeof(str));
}
}