编写一个程序,从键盘上输入一篇英文文章。首先输入英文文章的行数n(1≤n≤10),接着依次输入n行内容(每行少于80个字符)。要求统计出其中的英文字母(不区分大小写)、数字和其他非空白字符的个数。

具体可参考如下案例:

案例输入:

  1. 2
  2. 21st century is the century of technology.
  3. Nowadays, technology is everywhere around us.

案例输出:

  1. 英文字母:71
  2. 数字:2
  3. 其他字符: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;
}

版权声明:本文为weixin_51222289原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/weixin_51222289/article/details/109610538