/*
题目:
求字符串第一个只出现一次的字符。
*/
/*
思路:
使用map遍历两次,第一次计数,第二次找到计数为1的第一个字符。
*/
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
char FirstNotRepeatingChar(string str){
map<char,int> myMap;
int len = str.size();
if(len == 0) throw("invalid parameter");
for(int i = 0; i < len; i++){
if(myMap.count(str[i])){
myMap[str[i]]++;
}else{
myMap[str[i]] = 1;
}
}
for(int i = 0; i < len; i++){
if(myMap[str[i]] == 1){
return str[i];
}
}
}
int main(){
string str="abaccdeff";
cout<<FirstNotRepeatingChar(str);
return 0;
}