0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-08 15:18:46 +00:00

772. 只出现一次的字符

https://www.acwing.com/problem/content/submission/code_detail/6942793/
This commit is contained in:
Baoshuo Ren 2021-08-06 18:28:57 +08:00 committed by Baoshuo Ren
parent aedbc3fe09
commit 7f1abb0726
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

View File

@ -4,30 +4,20 @@ using namespace std;
int main() { int main() {
string s; string s;
vector<char> ans; map<char, int> m;
int a = -1; queue<char> q;
char c = 'a';
cin >> s; cin >> s;
map<char, int> m, m1; for (char i : s) {
for (int i = 0; i < s.size(); i++) { m[i]++;
m[s[i]]++; q.push(i);
if (!m1.count(s[i])) m1[s[i]] = i;
} }
for (char i = 'a'; i <= 'z'; i++) { while (!q.empty()) {
if (m[i] == 1) { if (m[q.front()] == 1) {
ans.push_back(i); cout << q.front() << endl;
exit(0);
} }
q.pop();
} }
if (ans.empty()) { cout << "no" << endl;
cout << "no" << endl;
} else {
for (char i : ans) {
if (a == -1 || m1[i] < a) {
a = m1[i];
c = i;
}
}
cout << c << endl;
}
return 0; return 0;
} }