複数行の文字を数える
記事を考えると、3行のテキストがあり、各行の最大文字数は80文字です。英語の大文字、小文字、数字、スペース、その他の文字の数を個別にカウントする必要があります。
入力記事を示す合計3行を入力します。
記事内の英語の大文字、小文字、数字、スペース、その他の文字の数をスペースで区切って1行に出力します。
行末出力に注意してください。
入る
I am a program.
This is the second line!
And this is the last line........
出力
3 47 0 12 10
//统计多行字符
#include<iostream>
#include<string>
#define N 80 //单行字符上限
using namespace std;
int main(void)
{
char a[3][N]; //三行
int i,j, up=0, low=0, num=0, sp=0, other=0;
for (i=0;i<3; i++)
gets(a[i]);
for (i=0;i<3;i++)
{
for (j=0;a[i][j]!='\0';j++)
{
if (a[i][j]>='A'&&a[i][j]<='Z')
up++;
else if (a[i][j]>='a'&&a[i][j]<='z')
low++;
else if (a[i][j]>='0'&&a[i][j]<='9')
num++;
else if (a[i][j]==' ')
sp++;
else other++;
}
}
cout<<up<<" "<<low<<" "<<num<<" "<<sp<<" "<<other<<" "<<endl;
return 0;
}