forked from Jonathan-Uy/CSES-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShortest Subsequence.cpp
More file actions
45 lines (39 loc) · 793 Bytes
/
Shortest Subsequence.cpp
File metadata and controls
45 lines (39 loc) · 793 Bytes
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;
const int maxN = 1e6+5;
int N, cnt;
char S[maxN], ch[4] = {'A', 'C', 'G', 'T'};
bool has[4];
vector<int> segs;
map<char,int> mp;
void init(){
mp['A'] = 0;
mp['C'] = 1;
mp['G'] = 2;
mp['T'] = 3;
}
int main(){
init();
scanf(" %s", S);
N = (int) strlen(S);
for(int i = 0; i < N; i++){
int c = mp[S[i]];
if(!has[c]){
has[c] = true;
cnt++;
if(cnt == 4){
fill(has, has+4, false);
segs.push_back(i);
cnt = 0;
}
}
}
for(int i : segs)
printf("%c", S[i]);
for(int i = 0; i < 4; i++){
if(!has[i]){
printf("%c\n", ch[i]);
return 0;
}
}
}