问题:找出字符串中第一个只出现一次的字符
输入描述:输入一个非空字符串
输出描述:输出第一个只出现一次的字符,如果不存在输出-1
具体代码如下:
#include <iostream>
using namespace std;
int main()
{
string s;
while(cin>>s)
{
int countarray[256]={0};
//1.统计次数(现在是绝对位置)
for(auto ch : s)
{
countarray[ch]++;
}
bool findflag=false;
for(auto ch: s)
{
if(countarray[ch]==1)
{
cout<<ch<<endl;
findflag=true;
break;
}
}
if(findflag==false)
cout<<-1<<endl;
}
return 0;
}