第一个只出现一次的字符

来源:互联网 发布:大数据的开放合作 编辑:程序博客网 时间:2024/06/05 14:12
题目:在一个字符串中找到第一个只出现一次的字符。如输入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;elsem.erase(*str);str++;}map<char,int>::iterator it=m.begin();if(it!=m.end())cout<<it->first;elsecout<<"不存在第一个只出现一次的字符"<<endl;return 0;}

0 0
原创粉丝点击