0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-11 22:46:28 +00:00

772. 只出现一次的字符

https://www.acwing.com/problem/content/submission/code_detail/6847872/
This commit is contained in:
Baoshuo Ren 2021-08-02 19:52:39 +08:00 committed by Baoshuo Ren
parent ceb66a4db8
commit c4a4e8ba38
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

33
AcWing/772/772.cpp Normal file
View File

@ -0,0 +1,33 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
vector<char> ans;
int a = -1;
char c = 'a';
cin >> s;
map<char, int> m, m1;
for (int i = 0; i < s.size(); i++) {
m[s[i]]++;
if (!m1.count(s[i])) m1[s[i]] = i;
}
for (char i = 'a'; i <= 'z'; i++) {
if (m[i] == 1) {
ans.push_back(i);
}
}
if (ans.empty()) {
cout << "no" << endl;
} else {
for (char i : ans) {
if (a == -1 || m1[i] < a) {
a = m1[i];
c = i;
}
}
cout << c << endl;
}
return 0;
}