mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-24 03:11:58 +00:00
772. 只出现一次的字符
https://www.acwing.com/problem/content/submission/code_detail/6942793/
This commit is contained in:
parent
aedbc3fe09
commit
7f1abb0726
@ -4,30 +4,20 @@ using namespace std;
|
||||
|
||||
int main() {
|
||||
string s;
|
||||
vector<char> ans;
|
||||
int a = -1;
|
||||
char c = 'a';
|
||||
map<char, int> m;
|
||||
queue<char> q;
|
||||
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 : s) {
|
||||
m[i]++;
|
||||
q.push(i);
|
||||
}
|
||||
for (char i = 'a'; i <= 'z'; i++) {
|
||||
if (m[i] == 1) {
|
||||
ans.push_back(i);
|
||||
while (!q.empty()) {
|
||||
if (m[q.front()] == 1) {
|
||||
cout << q.front() << endl;
|
||||
exit(0);
|
||||
}
|
||||
q.pop();
|
||||
}
|
||||
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;
|
||||
}
|
||||
cout << "no" << endl;
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user