一些练习——统计字符串中各种字符的个数
2014-12-19 22:55
232 查看
代码
运行结果:
#include <iostream> #include <cstdio> using namespace std; int main() { char ch[100]; gets(ch); int a=0,b=0,c=0,d=0,i=0; while(ch[i]!='\0') { if((ch[i]>='A'&&ch[i]<='Z')||(ch[i]>='a'&&ch[i]<='z')) a++; else if(ch[i]>='0'&&ch[i]<='9') b++; else if(ch[i]==' ') c++; else d++; i++; } cout<<"字母的个数:"<<a<<endl; cout<<"数字的个数:"<<b<<endl; cout<<"空格的个数:"<<c<<endl; cout<<"其他字符的个数:"<<d; return 0; }
运行结果:
相关文章推荐
- 统计字符串中字符个数一些有趣的事
- java循环练习:输入一个字符串,统计该字符串中分别包含多少个数字,多少个字母,多少个其他字符
- 统计字符串中各种字符的个数----函数//指针做法和非指针做法
- 字符串中各类字符统计的小练习
- HashMap练习统计字符串中每个字符出现的次数和HashMap嵌套HashMap
- java基础练习-统计字符串中每个字符出现的次数
- Java编程练习之判断Java文件名是否正确,判断邮箱格式是否正确和统计指定字符串中某字符现的次数
- java小练习之统计字符串中字符出现的次数
- String类练习讲解-统计字符串中出现连续字符的次数
- Scheme 练习 - 统计字符串中每个字符出现的次数
- C# ——输入 若干字符组成的字符串,写静态方法,统计并输出各种字符的数目
- C语言例题——统计字符串中各种字符
- java小练习之统计字符串中字符出现的次数
- C和指针之字符串编程练习11(统计一串字符包含the的个数)
- C#练习——去掉字符串两端的空格、统计字符出现的次数及出现的索引位置、随机生成10个1-100之间的不重复的偶数
- python小练习1:给一个字符串,统计其中的数字、字母和其他类型字符的个数
- 初学java:统计字符串中各种字符个数
- 练习三:统计字符串中字符中 大写字符 小写字符 数字 其他字符 出现的次数
- js统计字符串中各种字符情况
- 利用函数指针统计字符串中各种类型字符的个数