题解 | #找出字符串中第一个只出现一次的字符#
找出字符串中第一个只出现一次的字符
https://www.nowcoder.com/practice/e896d0f82f1246a3aa7b232ce38029d4
#include <iostream>
using namespace std;
int main()
{
string str;
while (getline(cin, str))
{
int a[128] = {0};
int len = str.size();
bool flag = false;
for (int i = 0; i < len; i++)
{
a[str[i]] += 1;
}
for (int i = 0; i < len; i++)
{
if (a[str[i]] == 1)
{
cout << str[i];
flag = true;
break;
}
}
if(!flag) cout << -1;
}
return 0;
}
查看4道真题和解析

