题解 | #找出字符串中第一个只出现一次的字符#
找出字符串中第一个只出现一次的字符
https://www.nowcoder.com/practice/e896d0f82f1246a3aa7b232ce38029d4
#include <iostream>
#include <string>
#include <set>
using namespace std;
int SumCount(int i, string s)
{
    int len = s.size();
    int count = 0;
    for(int j=0; j<len; j++)
    {
        if(s[j] == s[i])
        {
            count++;
        }
    }
    return count;
}
int main() 
{
   string s;
    getline(cin,s);
   int len = s.size();
   int count = 0;
   bool flag = false;
   for(int i =0; i<len; i++)
   {
        count = SumCount(i, s);
       if(count == 1)
       {
        flag = true;
        cout<<s[i]<<endl;
        break;
        return 0;
       } 
   }
   if(!flag)
   {
         cout<<"-1"<<endl;
   }
  
   return 0;
}
// 64 位输出请用 printf("%lld")
查看22道真题和解析
