统计字符串中有‘0’——‘9’的字符个数
来源:互联网 发布:mts钢结构设计软件 编辑:程序博客网 时间:2024/06/08 21:24
#include<iostream>using namespace std;int Cllcdigital(char *str){ if(NULL == str){ return 0; } int i = 0; int size = 0; int count[256] ={0}; char *sd = NULL; sd = str; while(*sd != '\0'){ count[*sd] = count[*sd] +1; sd++; } for(i = '0';i<= '9';i++) { size += count[i]; } return size;}int main(){ int size = 0; char str[] = "he1234llo,0909"; size = Cllcdigital(str); cout << size <<endl; return 0;}运行结果:8Press any key to continue
体会:
有点类似哈希算法的思想,想象有256个桶 ,
来一个元素,就将它放入桶中,每个桶中加一
就可求出
0 0
- 统计字符串中有‘0’——‘9’的字符个数
- 统计字符串中各个字符的个数
- 统计字符串中相同字符的个数
- 统计字符串中字符的个数
- 统计字符串中各个字符的个数
- 统计字符串中某个字符的个数
- 统计字符串中各个字符的个数
- 统计字符串中各种字符的个数
- 统计字符串中每个字符的个数
- 统计字符串中不同类型字符的个数
- 统计字符串中字符出现的个数
- 统计字符串中字符的个数
- 统计字符串中各字符的个数
- 统计字符串中,各个字符的个数
- 统计字符串中字符个数
- 统计任意长度字符串中各个字符及个数——计数排序的又一个应用
- Java面试(编程)——统计字符串中重复字符的个数
- 【字符串操作】03.统计字符串中各个字符的个数
- 在studio build.gradle配置MaterialDesignLibrary
- 好用的分类统计--Python
- studio2.0+ndk-r11 中jni编译问题
- 为什么time()函数要返回1970年1月1日00点00分00秒开始到现在的秒数
- 剑指offer 26题 【分解让复杂问题简单】复杂链表的复制
- 统计字符串中有‘0’——‘9’的字符个数
- 根据业务定制的一个本地分页插件
- ActiveMQ的简单使用
- 丑数
- GP学习(三)—How to run a geoprocessing tool
- 1/4像素运动估计
- TCP/UDP报文格式
- Android自定义View之画笔与画布
- java序列化接口Serializable的使用