-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1087.cc
45 lines (40 loc) · 822 Bytes
/
1087.cc
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
#include <bits/stdc++.h>
using namespace std;
constexpr int maxn = 1000010;
constexpr int alphabets = 4;
int pos[maxn][alphabets];
string s = "ACTG";
int GetID(char ch) {
for (int i = 0; i < s.size(); i++)
if (s[i] == ch)
return i;
return -1;
}
int main() {
string str;
cin >> str;
int N = str.size();
pos[N][0] = pos[N][1] = pos[N][2] = pos[N][3] = maxn;
for (int i = N - 1; i >= 0; i--) {
for (int j = 0; j < alphabets; j++)
pos[i][j] = pos[i + 1][j];
int id = GetID(str[i]);
pos[i][id] = i;
}
string ans = "";
int p = -1;
while (p < N) {
int mx = 0;
for (int i = 0; i < alphabets; i++)
mx = max(mx, pos[p + 1][i]);
for (int i = 0; i < alphabets; i++) {
if (pos[p + 1][i] == mx) {
ans += s[i];
p = pos[p + 1][i];
break;
}
}
}
cout << ans << "\n";
return 0;
}