|
|
|
@ -0,0 +1,40 @@
|
|
|
|
|
#include<stdio.h>
|
|
|
|
|
#include<string.h>
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
char str[10];
|
|
|
|
|
gets(str);
|
|
|
|
|
int cap = 0,low = 0,num = 0,space = 0,other = 0;
|
|
|
|
|
int i;
|
|
|
|
|
int len = strlen(str);
|
|
|
|
|
for(i = 0;i < len;i++)
|
|
|
|
|
{
|
|
|
|
|
if(str[i] >= 'A'&&str[i] <= 'Z')
|
|
|
|
|
{
|
|
|
|
|
cap++;
|
|
|
|
|
}
|
|
|
|
|
else if(str[i] >= 'a'&&str[i] <= 'z')
|
|
|
|
|
{
|
|
|
|
|
low++;
|
|
|
|
|
}
|
|
|
|
|
else if(str[i] >= '0'&&str[i] <= '9')
|
|
|
|
|
{
|
|
|
|
|
num++;
|
|
|
|
|
}
|
|
|
|
|
else if(str[i] == ' ')
|
|
|
|
|
{
|
|
|
|
|
space++;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
other++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
printf("大写字母:%d\n小写字母:%d\n数字:%d\n空格:%d\n其他:%d\n",cap,low,num,space,other);
|
|
|
|
|
/**
|
|
|
|
|
时间复杂度: 字符分类统计:若从键盘输入一个长度为n的字符串,分别统计出其中大写字母、小写字母、数字、空格和其他字符的个数并分别输出
|
|
|
|
|
当n在某个特定的范围内,在最优的情况下,其时间复杂度为O(n);
|
|
|
|
|
空间复杂度:字符分类统计的空间复杂度为S(n);
|
|
|
|
|
**/
|
|
|
|
|
}
|
|
|
|
|
}
|