-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring_del.cpp
More file actions
87 lines (74 loc) · 1.96 KB
/
Copy pathstring_del.cpp
File metadata and controls
87 lines (74 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <bits/stdc++.h>
using namespace std;
string clearDigits(string s) {
int n = s.size();
vector<int> check(n, 1);
for (int i = 0; i < n; i++) {
if (isdigit(s[i])) {
check[i] = 0;
int j = i - 1;
while (j >= 0 && isdigit(s[j])) {
j--;
}
s[j] = '1';
check[j] = 0;
}
}
string res = "";
for (int i = 0; i < n; i++) {
if (check[i]) {
res += s[i];
}
}
return res;
}
string clearDigits2(string s) {
int n = s.size();
stack<char>st;
for (int i = 0; i < n; i++) {
if (isdigit(s[i])) {
st.pop();
} else {
st.push(s[i]);
}
}
string res = "";
while (!st.empty()) {
res += st.top();
st.pop();
}
reverse(res.begin(), res.end());
return res;
}
int findWinningPlayer(vector<int>& skills, int k) {
unordered_map<int,int> mp;
int n = skills.size();
deque<int> dq;
for (int i = 0; i < n; i++) {
mp[skills[i]] = i;
dq.push_back(skills[i]);
}
int streak = 0;
int cur = -1;
while (streak != k) {
int first = dq.front();
dq.pop_front();
int second = dq.front();
dq.pop_front();
int winner = max(first, second);
int loser = min(first, second);
if (cur == winner) {
streak++;
} else {
streak = 1;
cur = winner;
}
dq.push_back(loser);
dq.push_front(winner);
}
return mp[cur];
}
int main() {
cout << clearDigits2("abc") << endl;
return 0;
}