输入一行字符,分别统计其中大写字母,小写字母,数字的个数
#include <iostream>
using namespace std;
int main()
{
char c;
int lettersmall = 0, letterbig = 0, digit = 0;
while ((c = getchar()) != '\n') //当输入不是空格
{
if (c >= 'a' && c <= 'z') //小写
lettersmall++;
else if (c >= 'A' && c <= 'Z') //大写
letterbig++;
else if (c >= '0' && c <= '9') //数字
digit++;
}
cout << "小写字母:" << lettersmall << " 大写字母:" << letterbig << " 数字:" << digit << endl;
return 0;
}
# include<stdio.h>
#include<math.h>
/*
输入一行字符,分别统计其中大写字母,
小写字母,数字的个数
*/
int main()
{
char str[1024] = {0};
int a, A, s;
a = A = s = 0;
scanf("%s",&str);
int i = 0;
while (str[i]!='\0')
{
if (str[i]>='a'&&str[i]<='z')
{
a++;
}
if (str[i] >= 'A' && str[i] <= 'Z')
{
A++;
}
if (str[i] >= '1' && str[i] <= '9')
{
s++;
}
i++;
}
printf("大写字母:%d,小写字母:%d,数字:%d",A,a,s);
return 0;
}