第十三周项目5-字符串操作:字符统计
来源:互联网 发布:鱼油哪个牌子好,知乎 编辑:程序博客网 时间:2024/06/05 08:13
#include<iostream>#include<cstdio> using namespace std;int main(){char str[50];int i=0,n=0;cout<<"输入字符串:";gets(str);while(str[i]!='\0'){ if(str[i]>='0'&&str[i]<='9') n++;i++;}cout<<"其中的数字个数是: "<<n<<endl;return 0;}
统计字母'A'出现的次数
/* *Copyright (c) 2014,烟台大学计算机学院 *All gight reserved. *文件名称:temp.cpp *作者:邵帅 *完成时间:2014年11月20日 *版本号:v1.0*/#include<iostream>#include<cstdio>using namespace std;int main(){char str[50];int i=0,n=0;cout<<"输入字符串:";gets(str);while(str[i]!='\0'){if(str[i]=='A') n++;i++;}cout<<"其中的字母A个数是: "<<n<<endl;return 0;}运行结果:
统计字符串中(大/小写)字母个数
/* *Copyright (c) 2014,烟台大学计算机学院 *All gight reserved. *文件名称:temp.cpp *作者:邵帅 *完成时间:2014年11月20日 *版本号:v1.0*/#include<iostream>#include<cstdio>using namespace std;int main(){ char str[50]; int i=0,n=0,m=0; cout<<"输入字符串:"; gets(str); while(str[i]!='\0') { if (str[i]>=65 && str[i]<=90) n++; else if (str[i]>=97 && str[i]<=122) m++; i++; } cout<<"其中的大写字母的个数是: "<<n<<endl<<"小写字母的个数是:"<<m; return 0;}运行结果:
统计每一个数字字符出现的次数
/* *Copyright (c) 2014,烟台大学计算机学院 *All gight reserved. *文件名称:temp.cpp *作者:邵帅 *完成时间:2014年11月20日 *版本号:v1.0*/#include<iostream>#include<cstdio>using namespace std;int main(){char str[50];int a[10];int i=0,n=0;for (n=0;n<10;n++) a[n]=0;cout<<"输入字符串:";gets(str);while(str[i]!='\0'){switch (str[i]){case '0':a[0]++;break;case '1':a[1]++;break;case '2':a[2]++;break;case '3':a[3]++;break;case '4':a[4]++;break;case '5':a[5]++;break;case '6':a[6]++;break;case '7':a[7]++;break;case '8':a[8]++;break;case '9':a[9]++;break;}i++;}for (n=0;n<10;n++) cout<<n<<"的个数为:"<<a[n]<<endl;return 0;}
运行结果:
统计每一个字母出现的个数
/* *Copyright (c) 2014,烟台大学计算机学院 *All gight reserved. *文件名称:temp.cpp *作者:邵帅 *完成时间:2014年11月20日 *版本号:v1.0*/#include<iostream>#include<cstdio>using namespace std;int main(){char str[50];int a[52];int i=0,n=0;char num;for (n=0;n<52;n++) a[n]=0;cout<<"输入字符串:";gets(str);while(str[i]!='\0'){switch (str[i]){case 'a':a[0]++;break;case 'b':a[1]++;break;case 'c':a[2]++;break;case 'd':a[3]++;break;case 'e':a[4]++;break;case 'f':a[5]++;break;case 'g':a[6]++;break;case 'h':a[7]++;break;case 'i':a[8]++;break;case 'j':a[9]++;break;case 'k':a[10]++;break;case 'l':a[11]++;break;case 'm':a[12]++;break;case 'n':a[13]++;break;case 'o':a[14]++;break;case 'p':a[15]++;break;case 'q':a[16]++;break;case 'r':a[17]++;break;case 's':a[18]++;break;case 't':a[19]++;break;case 'u':a[20]++;break;case 'v':a[21]++;break;case 'w':a[22]++;break;case 'x':a[23]++;break;case 'y':a[24]++;break;case 'z':a[25]++;break;case 'A':a[26]++;break;case 'B':a[27]++;break;case 'C':a[28]++;break;case 'D':a[29]++;break;case 'E':a[30]++;break;case 'F':a[31]++;break;case 'G':a[32]++;break;case 'H':a[33]++;break;case 'I':a[34]++;break;case 'J':a[35]++;break;case 'K':a[36]++;break;case 'L':a[37]++;break;case 'M':a[38]++;break;case 'N':a[39]++;break;case 'O':a[40]++;break;case 'P':a[41]++;break;case 'Q':a[42]++;break;case 'R':a[43]++;break;case 'S':a[44]++;break;case 'T':a[45]++;break;case 'U':a[46]++;break;case 'V':a[47]++;break;case 'W':a[48]++;break;case 'X':a[49]++;break;case 'Y':a[50]++;break;case 'Z':a[51]++;break;}i++;}for (n=0,num=97;n<26;n++,num++) cout<<num<<"的个数为:"<<a[n]<<endl; for (n=0,num=65;n<26;n++,num++) cout<<num<<"的个数为:"<<a[n]<<endl;return 0;}运行结果:
@ Mayuko
0 0
- 第十三周项目字符串操作 字符统计
- 第十三周项目5-字符串操作:字符统计
- 第十三周项目 5 字符串操作(字符统计)——A的出现次数
- 第十三周项目5字符串操作统计字符'A'出现的次数
- 第十三周项目 5 字符串操作(字符统计)——统计其中大小写字母的个数
- 第十三周 项目五--字符串操作(1.1)字符统计功能
- 第十三周 项目五--字符串操作(1.3)统计每个字符出现次数
- 第十三周项目五字符串操作(1)统计每一个数字字符出现的次数
- 第十三周项目5-1:字符统计
- 第十三周 项目五--字符串操作(1.4)字母统计
- 第十三周上机项目5--(3) 字符串中字符数目的统计
- 第十三周项目5字符串操作统计字符串中大小写的个数
- 第13周项目5-字符串操作--字符统计
- 第十三周项目5-字符串的操作(统计字母 ' A ' 出现的次数)
- 第十三周项目5-字符串的操作(统计大小写字母)
- 第十三周项目5-字符串操作(统计每一个字母出现的个数)
- 第十三周项目5-字符串的操作(统计每一个数字出现的个数)
- 第十三周项目5-字符串操作5
- 通过rowid逻辑并行抽取数据
- socket 与 vfs
- 线性表(二)
- Rattle :基于R的数据挖掘工具(4b):探索数据
- java常用设计模式
- 第十三周项目5-字符串操作:字符统计
- 第三天学习
- 异常处理系列:Exception in thread "main" org.hibernate.HibernateException: Javassist Enhancement failed:cn.
- openwrt安装内核模块* satisfy_dependencies_for
- select 下拉列表可编辑
- 通过C#理解多态
- win7 64bit IIS相关设置
- Problem A: Artificial Intelligence?
- ICP算法(Iterative Closest Point)及VTK实现(改)