2024.3.11

该C++代码通过main函数接收用户输入的字符串,统计其中大写字母、小写字母、数字、空格和非ASCII字符的数量,并输出结果。
摘要由CSDN通过智能技术生成

作业:

#include <iostream>
#include<iomanip>
#include<string>
using namespace std;

int main()
{
      string str;
//    array<char,128> a;
//    array<char,128>::iterator iter;
    cout << "请输入一个字符串:" << endl;
    getline(cin,str);
    int b = str.size();
   // char *p=(char *)&str;


//    for(int j=0;j<b;j++)
//    {
//        cout << *(p+j);
//    }


    int big=0,little=0,num=0,blank=0,other=0;

    for(int i=0;i<b;i++)
    {
        if(str.at(i)>='A' && str.at(i)<='Z')
        {
            big++;
            continue;
        }
        if(str.at(i)>='a' && str.at(i)<='z')
        {
            little++;
            continue;
        }
        if(str.at(i)>=0 && str.at(i)<=9)
        {
            num++;
            continue;
        }
        if(str.at(i)==' ')
        {
            blank++;
            continue;
        }
        else
        {
            other++;
            continue;
        }
    }
    cout << "big =" << big << endl;
    cout << "little =" << little << endl;
    cout << "num =" << num << endl;
    cout << "blank =" << blank << endl;
    cout << "other =" << other << endl;

    return 0;
}

思维:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值