[Code Jam 2022 Round 1A] Double or One Thing

Double or One Thing

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
#include <bits/stdc++.h>
using namespace std;

string solve(string& s) {
string res = "";
for(int i = 0; i < s.length() - 1; i++) {
if(s[i] > s[i+1])
res.push_back(s[i]);
else if(s[i] < s[i+1]) {
res.push_back(s[i]);
res.push_back(s[i]);
} else if(s[i] == s[i+1]) {
int find = 0;
for(int j = i + 2; j < s.length() and find == 0; j++) {
if(s[j] > s[i]) find = 1;
else if(s[j] < s[i]) find = -1;
}
res.push_back(s[i]);
if(find == 1)
res.push_back(s[i]);
}
}
return res + s.back();
}

int main() {
int tc;
cin>>tc;
for(int i = 1; i <= tc; i++) {
string s;
cin>>s;
cout<<"Case #"<<i<<": "<<solve(s)<<endl;
}
return 0;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2022/04/09/PS/Google/double-or-one-thing/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.