谭浩强c++第五章题10 有一篇文章,共有3行文字,每行有80个字符。要求分别统计出其中英文大写字母、小写字母、数字、空格以及其他字符的个数。

 自己写的没这个好 参考的:https://blog.csdn.net/navicheung/article/details/81280427

#include <iostream>
#include <string>
using namespace std;
int main()
{
    char str[3][80];
    int upper, lower, num, space, other, i, j;
    for (i=0; i<3; i++){
        cout<<"Please enter row "<<i+1<<" string: ";
        gets(str[i]);
    }
    for (i=0; i<3; i++){
        for (j=0, upper=0, lower=0, num=0, space=0, other=0; str[i][j]!='\0'; j++){
            if (str[i][j]>='A'&&str[i][j]<='Z') upper++;
            else if (str[i][j]>='a'&&str[i][j]<='z') lower++;
            else if (str[i][j]>='0'&&str[i][j]<='9') num++;
            else if (str[i][j]==' '||str[i][j]=='\t') space++;
            else other++;
        }
        cout<<str[i]<<"\nUpper= "<<upper<<" Lower= "<<lower<<" Number= "<<num<<" Space="<<space<<" Ohter="<<other<<endl;
    }
    system("pause");
    return 0;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值