C++——输入一行文字,找出其中的大写字母、小写字母、空格数字以及其他字符各有多少。用指针或引用方法处理。

没注释的源代码

#include <iostream>

using namespace std;

int main()
{
    char c;
    int ul=0,ll=0,sp=0,di=0,other=0;
    cout<<"please input script c:";
    while(cin.get(c))
    {
        if(c=='\n') break;
        else if(c>='A'&&c<='Z') ul++;
        else if(c>='a'&&c<='z') ll++;
        else if(c==' ') sp++;
        else if(c>='0'&&c<='9') di++;
        else other++;
    }
    cout<<"number of uppercase letters:"<<ul<<endl;
    cout<<"number of lowercase letters:"<<ll<<endl;
    cout<<"number of space:"<<sp<<endl;
    cout<<"number of digits:"<<di<<endl;
    cout<<"number of other:"<<other<<endl;
    return 0;
}
 

猜你喜欢

转载自blog.csdn.net/2303_80770781/article/details/143268177