题目
c++输入一行字符,分别统计出其中英文字母,空格,数字字符和其它字符的个数.
用cin.get(c)函数从键盘上输入一个字符给变量c,直到输入回车换行字符'\n'为止.
用cin.get(c)函数从键盘上输入一个字符给变量c,直到输入回车换行字符'\n'为止.
提问时间:2020-10-17
答案
#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;
}
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;
}
望采纳!
举一反三
已知函数f(x)=x,g(x)=alnx,a∈R.若曲线y=f(x)与曲线y=g(x)相交,且在交点处有相同的切线,求a的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
最新试题
- 1冯骥才日历北师大课后练习题~
- 2三角方程tan3x+tanx=0在[0,pai]内解的个数为?
- 33.24的平方根是多少?
- 4在制取镁单质或螑单质的过程中,卤水指的是什么呢?
- 5Heidi_____(teach)at this primary school since she__-school five years ago.
- 6『求解』有谁知道 多少 乘以 多少 等于 1234567654321 这是一个奥数题!
- 7人的基础代谢率怎么计算?查看一天消耗的热量,是不是一天所有运动消耗的热量+基础消耗?还是已经包含在内
- 8下表是某品牌小轿车的一些技术参数.其中排气量是指发动机气缸的工作容积,一般情况下,发动机的排气量越大,功率越大.空燃比是指气缸内空气和燃油的质量比.汽油的热值表示每千
- 9难题:算一算:浇注这个柱子需要多少立方分米混凝土?
- 10学校开展为地震灾区献爱心活动,六一班和六二班都有40名同学,六一班平均每人捐款四分之二十三元,六二班平均每人捐款五分之二十四元,两个班同学一共捐款多少元?
热门考点
- 1Study for some time each class day.
- 2圆柱体的底面半径是两厘米那么圆柱体的底面积是多少平方厘米?
- 39()8()7()6()5()4()3()2()1=23,的八个括号中,适当填入“+”或“—”号,等式成立,不同的填法共有多少种
- 4I hope __soon.A.him to feel well B.he feels good C.him to feel good D.he feels better
- 5同位语从句 和 定语从句 的区别?
- 6一道线性代数题X 2 1 0,1 3X -1 1,3 4 2X -2,1 1 - 1 X 求X3次方的系数/
- 7导数的应用
- 8有一道数学题,用算术方法解
- 9电荷在某处不受电场力的作用,则该处电场强度为零.通电导线在某处不受电场力的作用,则该处磁感应强度为零.
- 10baby ,can you give me Forever /ove?