|
|
|
|
@ -0,0 +1,38 @@
|
|
|
|
|
字符分类统计:从键盘输入一个长度为10的字符串,分别统计出其中大写字母、小写字母、数字、空格和其他字符的个数并分别输出。
|
|
|
|
|
代码:
|
|
|
|
|
#include<stdio.h>
|
|
|
|
|
#include<string.h>
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
char str[100];
|
|
|
|
|
int i,num = 0,space = 0,capital = 0,lowercase = 0,others = 0;
|
|
|
|
|
gets(str);
|
|
|
|
|
for(i=0; i<strlen(str); i++)
|
|
|
|
|
{
|
|
|
|
|
for(i=0; str[i]!='\0'; i++)
|
|
|
|
|
{
|
|
|
|
|
if(str[i]>='0'&&str[i]<='9')
|
|
|
|
|
num++;
|
|
|
|
|
if(str[i] ==' ')
|
|
|
|
|
space++;
|
|
|
|
|
if(str[i]>='A'&&str[i]<='Z')
|
|
|
|
|
capital ++;
|
|
|
|
|
if(str[i]>='a'&&str[i]<='z')
|
|
|
|
|
lowercase++;
|
|
|
|
|
else
|
|
|
|
|
others++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
printf("数字数量为:%d\n大写字母数量为:%d\n小写字母数量为:%d\n空格数量为:%d\n其他字符:%d\n",num,capital,lowercase,space,others);
|
|
|
|
|
}
|
|
|
|
|
运行结果时间:
|
|
|
|
|
ADxe12. ;
|
|
|
|
|
数字数量为:2
|
|
|
|
|
大写字母数量为:2
|
|
|
|
|
小写字母数量为:2
|
|
|
|
|
空格数量为:1
|
|
|
|
|
其他字符:7
|
|
|
|
|
|
|
|
|
|
--------------------------------
|
|
|
|
|
Process exited after 10.28 seconds with return value 0
|
|
|
|
|
请按任意键继续. . .
|