统计字符串中第一个出现次数为1的字符
2012-08-21 15:05
316 查看
用类似位图的办法,只是用数字实现。利用数组统计每个字符出现的次数,然后扫描第一个次数为1的元素
#include "stdafx.h" #include<iostream> #include<map> #include<algorithm> using namespace std; char findSingle(char *str)//一遍扫描法 { int count[256]={0};//这里都是小写字母,所以大小是26,也可以设置为256 char *p = str; while(*p != '\0') { count[*p]++; p++; } for(int i=0;i<256;i++) { if(count[i] == 1) { return static_cast<char>(i); } } } int main() { char *str="fsdfasfdiarewtrewtrew"; cout<<findSingle(str)<<endl; getchar(); return 0; }
相关文章推荐
- 统计字符串中第一个出现次数为1的字符
- 统计字符串中第一个出现次数为1的字符
- oracle统计字符串中某个字符出现的次数详解
- C语言:编写一个程序统计输入字符串中,各个数字、空白字符、以及其他所有字符出现的次数。
- 华为机试题---统计并输出每个字符在字符串中出现的次数
- 统计某java文件中的代码行数、某个字符(char)、某字符串(String)出现的次数
- 字符串压缩--统计字符出现的最大次数
- 判断一个字符串中出现次数最多的字符,统计这个次数
- Java统计字符串中出现次数最多的字符及其次数
- 搜索出字符串中出现次数最多的字符,并统计次数
- JavaScript统计字符串中每个字符出现次数完整实例
- JS实现找到某字符串中出现次数最多的字符,并统计次数
- js——统计字符串中每种字符出现的次数,出现次数最多的是? 出现?次
- Dictionary<>练习题:统计字符串中每个字符出现的次数
- 判断一个字符串出现次数最多的字符,统计该字符出现的次数
- 线性时间内统计一个字符串中每个字符出现的次数
- 【C语言】编写一个程序统计输入字符串中: 各个数字、空白字符、以及其他所有字符出现的次数。
- 统计字符串中每个字符出现的次数
- Java_基础—统计字符串中每个字符出现的次数
- oracle统计字符串中某个字符出现的次数