c++ “输入一行字符,分别统计其中的英文字母、数字字符、空格和其它字符的个数。”这个用c语言怎么写?

如题所述

#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;}
望采纳!

以上回答你满意么?
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2017-09-25
#include<iostream>

using namespace std;

int main()
{
int CAPS=0,LOW=0,NUM=0,OTHER=0,SPACE=0;

char a;

cout<<"Please input your char……"<<endl;

cin.get(a);

while(a!='\n'){

cin.get(a);

if(a>='1'&&a<='9')
NUM++;
else if(a>'A'&&a<'Z')
CAPS++;
else if(a>'a'&&a<'z')
LOW++;
else if(a==' ')
SPACE++;
else
OTHER++;
}
cout<<"CAPS:"<<CAPS<<endl<<"LOW:"<<LOW<<endl<<"NUM:"<<NUM<<endl<<"OTHER:"<<OTHER<<endl<<"SPACE:"<<SPACE<<endl;

return 0;
}
这个好像不能识别一些功能件,用汇编就可以,如esc键;本回答被提问者和网友采纳
相似回答