您的位置:首页 > 其它

【二维数组】统计英文大写字母,小写字母,数字,空格,以及其他字符的个数

2013-01-14 16:56 309 查看
/* 

* 程序的版权和版本声明部分: 

* Copyright (c) 2012, 烟台大学计算机学院 

* All rights reserved. 

* 文件名称:【二维数组】统计英文大写字母,小写字母,数字,空格,以及其他字符的个数.cpp 

* 作    者:毛通 

* 完成日期:2013 年 1月 日 

* 版 本 号:v1.0 

* 对任务及求解方法的描述部分:

* 输入描述:输入三行字符 可以随便输入

* 问题描述:统计输入字符的英文大写字母,小写字母,数字,空格,以及其他字符的个数 

* 问题分析:略

* 算法设计:略

*/

 

# include <iostream>

using namespace std;

int main()
{

int i,j,upper,lower,digit,space,other;
char text[3][80];

upper=lower=digit=space=other=0;

for(i=0;i<3;i++)
{
cout<<"Please input line "<<i+1<<endl;

gets(text[i]);

for(j=0;j<80 && text[i][j]!='\0';j++)
{
if(text[i][j]>='A' && text[i][j]<='Z')
upper++;
else if(text[i][j]>='a' && text[i][j]<='z')
lower++;
else if(text[i][j]>='0' && text[i][j]<='9')
digit++;
else if(text[i][j]==' ')
space++;
else
other ++;
}
}

cout<<"大写字母个数:"<<upper<<endl;
cout<<"小写字母个数:"<<lower<<endl;
cout<<"数字个数:"<<digit<<endl;
cout<<"空格个数:"<<space<<endl;
cout<<"其他个数:"<<other<<endl;

return 0;
}


/*

运行结果:



*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐