字符串统计

来源:互联网 发布:鲁大师 硬件体检 优化 编辑:程序博客网 时间:2024/05/18 03:45
/** 程序的版权和版本声明部分* Copyright (c)2013, 烟台大学计算机学院学生* All rightsreserved.* 作    者:冯冬影* 完成日期:2013  年11  月 30日* 版本号: v1.0* 输入描述:输入字符串* 问题描述:计算出大小写字母、数字的个数,* 程序输出:输出符合要求的个数* 问题分析:*/#include <iostream>#include <cstdio>using namespace std;int main (){    char str[50];    int i=0,n=0,g=0,j=0,k=0;    cout <<"输入字符串:";    gets (str);    while (str[i]!='\0')    {        if(str[i]>='0'&&str[i]<='9')        n++;        if(str[i]=='A') g++;        if(str[i]>='a'&&str[i]<='z') j++;        if(str[i]>='A'&&str[i]<='Z') k++;        i++;    }    cout<<"其中的数字个数是:"<<n<<endl;    cout <<"其中A的个数是:"<<g<<endl;    cout<<"其中的大写字母个数是:"<<k<<endl;    cout <<"其中的小写字母个数是:"<<j<<endl;    return 0;}

运行结果
原创粉丝点击