题目本来很简单,想用map实现,但还是too young,动手太少,代码很简单:
#include<iostream>
#include<map>
#include<string>
using namespace std;
int main()
{
string str;
char temp;
bool flag=false;
map<char,int> word;
getline(cin,str);
for(int i=0;i<str.size();++i)
++word[str[i]];
for(int i=0;i<str.size();++i)
{
temp=str[i];
if(word[temp]==1)<span style="white-space:pre"> </span>//开始错写成if(word.count(temp)==1)
{
flag=true;
break;
}
}
if(flag==false)
temp='.';
cout<<temp<<endl;
//system("pause");
return 0;
}
我就纳闷怎么答案不对呢,原来时间太长忘了count的功能是对键的计数,对map而言,count返回值只能是0或1