编写一个程序,从键盘上输入一篇英文文章。首先输入英文文章的行数n(1≤n≤10),接着依次输入n行内容(每行少于80个字符)。要求统计出其中的英文字母(不区分大小写)、数字和其他非空白字符的个数。
具体可参考如下案例:
案例输入:
- 2
- 21st century is the century of technology.
- Nowadays, technology is everywhere around us.
案例输出:
- 英文字母:71
- 数字:2
- 其他字符:3
#include <iostream>
using namespace std;
int main()
{
int n,i=0,x=0,y=0,z=0;
cin>>n;cin.get();
char str[800];
while((str[i]=cin.get())!=EOF)//EOF(Ctrl+z)输入结束
{
if((str[i]<=90&&str[i]>=65)||(str[i]<=122&&str[i]>=97))
x++;
else if(str[i]>=48&&str[i]<=57)
y++;
else if(str[i]==' '||str[i]=='\n')
{
x=x;
y=y;
z=z;
}
else
z++;
i++;
}
cout<<"英文字母:"<<x<<endl;
cout<<"数字:"<<y<<endl;
cout<<"其他字符:"<<z<<endl;
}