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

来源:互联网 发布:电子杂志免费制作软件 编辑:程序博客网 时间:2024/05/06 17:19

/* 
* 程序的版权和版本声明部分: 
* 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++;elseother ++;}}cout<<"大写字母个数:"<<upper<<endl;cout<<"小写字母个数:"<<lower<<endl;cout<<"数字个数:"<<digit<<endl;cout<<"空格个数:"<<space<<endl;cout<<"其他个数:"<<other<<endl;return 0;}


/*
运行结果:


*/

原创粉丝点击