先看看实现:
#include "iostream"
#include "windows.h"
#include "map"
#include "vector"
#include "algorithm"
#include "iterator"
#include "string"
using namespace std;
int main()
{
vector<char> coll;
copy(istream_iterator<char>(cin),istream_iterator<char>(),back_inserter(coll));
map<char,int> counts;
char word;
BOOL IsCheck=false;
for(int i=0; i<coll.size(); ++i)
{
word=coll.at(i);
++counts[word];
}
for(int j=0; j<coll.size(); j++)
{
char cha=coll.at(j);
map<char,int>::iterator num(counts.find(cha));
if(num==counts.end())
{
cout<<"查找出错!"<<endl;
}
if(num->second==1&&IsCheck==false)
{
cout<<num->first<<endl;
IsCheck=true;
}
}
system("pause");
return 0;
}
主要就是map数据结构的应用。