字符统计1
Time Limit: 1000 ms / Memory Limit: 65536 kb
Description
给出一串字符,要求统计出里面的字母、数字、空格以及其他字符的个数。
字母:A, B, ..., Z、a, b, ..., z组成
数字:0, 1, ..., 9
空格:" "(不包括引号)
剩下的可打印字符全为其他字符。
Input
测试数据有多组。
每组数据为一行(长度不超过100000)。
数据至文件结束(EOF)为止。
Output
每组输入对应一行输出。
包括四个整数a b c d,分别代表字母、数字、空格和其他字符的个数。
Sample Input
A0 ,
Sample Output
1 1 1 1
Source
ZJGSU
Submit
#include<string.h>
#include<stdio.h>
int main()
{
int n = 0;
char str[100001] ;
while (gets(str) != NULL )
{
int num = 0, word = 0, cha = 0, other = 0;
n = strlen(str);
for (int i = 0; i < n; i++)
{
if (((int)str[i] >= 65 && (int)str[i] <= 90) || ((int)str[i] >= 97 && (int)str[i] <= 122))
{
word++;
}
else if (((int)str[i] >= 48 && (int)str[i] <= 57))
{
num++;
}
else if (str[i] == ' ')
{
cha++;
}
else
{
other++;
}
}
printf("%d %d %d %d\n", word, num, cha, other);
}
return 0;
}
字符统计1
Time Limit: 1000 ms / Memory Limit: 65536 kb
Description
给出一串字符,要求统计出里面的字母、数字、空格以及其他字符的个数。
字母:A, B, ..., Z、a, b, ..., z组成
数字:0, 1, ..., 9
空格:" "(不包括引号)
剩下的可打印字符全为其他字符。
Input
测试数据有多组。
每组数据为一行(长度不超过100000)。
数据至文件结束(EOF)为止。
Output
每组输入对应一行输出。
包括四个整数a b c d,分别代表字母、数字、空格和其他字符的个数。
Sample Input
A0 ,
Sample Output
1 1 1 1
Source
ZJGSU