字符串统计
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
char str[50];
int i=0,n=0,m=0,x=0,l=0;
cout<<"输入字符串:";
gets(str);
while(str[i]!='\0')
{
if(str[i]>='0'&&str[i]<='9') n++;
if(str[i]>='a'&&str[i]<='z') m++;
if(str[i]>='A'&&str[i]<='Z') x++;
if(str[i]=='A') l++;
i++;
}
cout<<"其中的数字个数是: "<<n<<endl;
cout<<"其中的小写字母个数是: "<<m<<endl;
cout<<"其中的大写字母个数是: "<<x<<endl;
cout<<"其中A的次数是:"<<l<<endl;
return 0;
}
浙公网安备 33010602011771号