本题要求编写程序,输入N个字符,统计其中英文字母、数字字符和其他字符的个数。
输入格式:
输入在第一行中给出正整数N,第二行输入N个字符,最后一个回车表示输入结束,不算在内。
输出格式:
在一行内按照
letter = 英文字母个数, digit = 数字字符个数, other = 其他字符个数
的格式输出。请注意,等号的左右各有一个空格,逗号后有一个空格。
输入样例:
在这里给出一组输入。例如:
10
aZ &
09 Az
输出样例:
在这里给出相应的输出。例如:
letter = 4, digit = 2, other = 4
#include <stdio.h>
int letter = 0, digit = 0, other = 0, n;
char ch;
int a;
int main()
{
scanf("%d", &n);
int i = 1;
while (i <= n)
{
ch = getchar();
if (ch != '\n')
{
if ('0' <= ch && ch <= '9')
{
digit++;
}
else if (('A' <= ch && ch <= 'Z') || ('a' <= ch && ch <= 'z'))
{
letter++;
}
else
{
other++;
}
i++;
}
else
{
continue;
}
}
printf("letter = %d, digit = %d, other = %d", letter, digit, other);
return 0;
}