描述
有一篇文章,有多行文字,总字符数不超过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++;elsee++;
}
}
cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl;
return 0;
}
本文链接:https://my.lmcjl.com/post/15964.html
4 评论