CSES - Shared codeLink to this code:
https://cses.fi/paste/a2a91541a67d3154e716e/
#include <bits/stdc++.h>
using namespace std;
const string fix = "ACGT";
constexpr int maxn = 1e6 + 4;
int mp[1 << 7];
char s[maxn];
void solve() {
cin >> s;
string ans;
int matched = 0, n = strlen(s);
for (int j = 0 ; j < n; ++j) {
char i = s[j];
int x = ++mp[i];
if (x == 1) {
++matched;
}
if (matched == 4) {
ans += i;
for (char c: fix) mp[c] = 0;
matched = 0;
}
}
if (!matched) {
ans += 'A';
}
else {
for (char i: fix) {
if (!mp[i]) {
ans += i;
break;
}
}
}
cout << ans << '\n';
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
solve();
return 0;
}