hashmap可以把相同的key统计次数。

#include <algorithm>
#include <map>
#include <unordered_map>

using namespace std;

int main() {
    string str;
    while(cin>>str){
        unordered_map<char, int> m;
        for(int i = 0;i<str.size();i++){
            m[str[i]]++;
        }
        int pos=-1;
        for(int j = 0;j<str.size();j++){
            if(m[str[j]]==1) {pos=j;break;}
            
        }
        if(pos==-1) cout<<-1;
        else cout<<str[pos];
        
        
    }
}