题解 | #统计字符#
统计字符
http://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5
#include <stdio.h>
int main()
{
char str[1000] = {0};
int a[4] = {0};
gets(str);
int len = strlen(str);
for(int i = 0; i < len; i++)
{
if(str[i] >= 'A' && str[i] <= 'Z'
|| str[i] >= 'a' && str[i] <= 'z')
{
a[0]++;
}
else if(str[i] == ' ')
{
a[1]++;
}
else if(str[i] >= '0' && str[i] <= '9')
{
a[2]++;
}
else
{
a[3]++;
}
}
for(int i = 0; i < 4; i++)
{
printf("%d\n", a[i]);
}
return 0;
}