题解 | #统计字符#
统计字符
http://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5
#include <stdio.h>
#include <ctype.h>
static char g_string[1001] = {0};
static short g_num[4] = {0};
int main(int argc, char** argv)
{
gets(g_string);
for (int i = 0; i < strlen(g_string); i++) {
if (isalpha(g_string[i])) g_num[0]++;
else if (isspace(g_string[i])) g_num[1]++;
else if (isdigit(g_string[i])) g_num[2]++;
else g_num[3]++;
}
for (int i = 0; i < 4; i++) printf("%d\n", g_num[i]);
return 0;
}