c++输入一行字符,分别统计出其中英文字母,空格,数字字符和其它字符的个数.

问题描述:

c++输入一行字符,分别统计出其中英文字母,空格,数字字符和其它字符的个数.
用cin.get(c)函数从键盘上输入一个字符给变量c,直到输入回车换行字符'\n'为止.
1个回答 分类:综合 2014-10-31

问题解答:

我来补答
#include <iostream>
using namespace std;
int main()
{
     char c;
     int el=0,sp=0,nu=0,other=0; 
     
     while(cin.get(c))
     {
             if(c=='\n')
                        break;
             if((c>='A' && c<='Z')||(c>='a' && c<='z'))
                  el++;
             else if(c>='0'&&c<='9')
                 nu++;
             else if(c==' ')
                 sp++;
             else 
                  other++;
     }
     cout<<"英文字母个数="<<el<<endl<<"数 字 个 数 ="<<nu<<endl<<"空 格 字 数 ="<<sp<<endl<<"其他字符个数="<<other<<endl;
     system("pause");
     return 0;
}望采纳!
 
 
展开全文阅读
剩余:2000