文字信息统计

/*文字信息统计*/
/*用户输入一段文体(英文),统计
其字符的个数,大写字母的个数,小
写字母的个数,数字个数,及其他字
符的个数*/
#include<iostream>
using namespace std;
int main()
{
    const int N=101;//说明一个符号表示常量
    char str[N];//定义字符数组
    int len=0,capital=0,smallletter=0,digit=0,others=0;//len表长度,capital表大写字母,smallletter表小写字母,digit表数字,others表其他
    int i;
    cin.getline(str,N);//cin.getline(<字符数组名>,<字符长度>)可以读取带空格的一行字符串
    i=0;
    while(str[i]!='\0')
    {
        len++;
        if(str[i]<='Z'&&str[i]>='A')
            capital++;
        else if(str[i]<='z'&&str[i]>='a')
            smallletter++;
        else if(str[i]<='9'&&str[i]>='0')
            digit++;
        else
            others++;
            i++;
    }
    cout<<"长度:"<<"len="<<len<<endl;
    cout<<"大写字母:"<<"capital="<<capital<<endl;
    cout<<"小写字母:"<<"smallletter="<<smallletter<<endl;
    cout<<"数字个数:"<<"digit="<<digit<<endl;
    cout<<"其他字符:"<<"others="<<others<<endl;
        return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值