1016-统计字符

描述

有一篇文章,有多行文字,总字符数不超过5000。要分别统计出其中的英文大写字母,小写字母,数字,空格以及其他字符的个数。

输入
输入为单组测试数据。

输入有多行,多少行不确定。但是输入的字符总数不会超出5000.

输出
输出有5个数,分别表示整篇文章的英文大写字母,小写字母,数字,空格以及其他字符的个数。

每两个数之间用空格隔开。
输入样例:Also known as advanced fee fraud (AFF), 4-1-9 scams are named after the section of the Nigerian penal code that deals with fraud. Although originally originating in Nigeria these scams can originate from anywhere. If you fall for one of these at best you will lose thousands of dollars; at worst you will lose your life. These usually start with an email from a bank official or the relative of a recently deceased African president or a government minister informing you that they have access to millions of dollars but need your help to get the money out of the country. The end result is that when the deal is threatened you will be asked for money to secure the release of the funds. Do not under any circumstances reply to these letters, people have been murdered while following up with these scams.
输出样例:12 635 3 142 13
使用getline()函数可以读取字符串里的空格,它的参数是输入流对象和string对象

#include<iostream>
#include<string>

using namespace std;
int main()
{
string s;
int i,a,b,c,d,e;
a=b=c=d=e=0;
while(getline(cin,s))
{
for(i=0;i<s.size();i++)
{
    if(s[i]>='A'&&s[i]<='Z')
        a++;
    else if(s[i]>='a'&&s[i]<='z')
        b++;
    else if(s[i]>='0'&&s[i]<='9')
        c++;
    else if(s[i]==' ')
        d++;
    else
        e++;
}
} 
cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl;
return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值