zl程序教程

您现在的位置是:首页 >  其他

当前栏目

字符串统计

统计 字符串
2023-09-11 14:20:12 时间
#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;
}