#include <iostream>
#include <assert.h>
#include <map>
using namespace std;
char findFirstOne(char* str){
if(str==NULL)
return NULL;
map<char,int> table;
char* p=str;
while(*p!='\0'){
table[*p]++;
p++;
}
p=str;
while(*p!='\0'){
if(table[*p]==1)
return *p;
p++;
}
return NULL;
}
void main(){
char* str="hello world";
cout<<findFirstOne(str)<<endl;
str="hheelloo";
cout<<findFirstOne(str)<<endl;
str="hhello";
cout<<findFirstOne(str)<<endl;
system("pause");
}
第一个只出现一次的字符
最新推荐文章于 2020-06-12 12:50:39 发布