用户输入字符串,python统计大写、小写,数字的个数

用户输入字符串,python统计大写、小写,数字的个数python 3.6

#include <stdio.h>
int main()
{
char str[256];
char *p;
int upper = 0;
int lower = 0;
int space = 0;
int digit = 0;
int other = 0;
p = str; // P指针指向数组第一个元素 str[0]
gets(p);

while(*p) // P不为空的时候继续下面的
{
if(*p>='A' && *p<='Z') // 判断是否为大写
{
upper++; // 统计大写字母个数
}
else if(*p>='a' && *p<='z') //是否为小写
{
lower++; //统计小写个数
}
else if(*p == ' ') // 判断是否为“ ”
{
space++; //统计个数
}
else if(*p>='0' && *p<='9') // 判断是否为数字
{
digit++; // 统计数字个数
}
else
{
other++; //剩下的是其他字符的 统计个数
}
p++; //指针后移
}
printf("upper = %d\n",upper); // 输出
printf("lower = %d\n",lower); // 输出
printf("space = %d\n",space);// 输出
printf("digit = %d\n",digit);// 输出
printf("other = %d\n",other);// 输出
return 0;
}
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答