题目:在一个字符串中找到第一个只出现一次的字符。如输入abaccdeff,则输出b。
#include<iostream>
#include<map>
#include<stdio.h>
using namespace std;
int main()
{
char *str="abaccdeff";
map<char,int>m;
while(*str!=0)
{
if(m[*str]==0)
m[*str]=1;
else
m.erase(*str);
str++;
}
map<char,int>::iterator it=m.begin();
if(it!=m.end())
cout<<it->first;
else
cout<<"不存在第一个只出现一次的字符"<<endl;
return 0;
}
转载请注明原文地址: https://ju.6miu.com/read-969045.html