-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLiveCoding2.cpp
More file actions
47 lines (38 loc) · 873 Bytes
/
LiveCoding2.cpp
File metadata and controls
47 lines (38 loc) · 873 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
46
47
#include <iostream>
#include <vector>
using std::vector;
using std::string;
using std::cout;
using std::cin;
int main(){
cin.tie(0);
cout.tie(0);
std::ios_base::sync_with_stdio(false);
int N;
cin >> N;
int input[N];
for(int i = 0; i < N; i++){
cin >> input[i];
}
string ans = "a";
char letter = 'a', next;
for(int i = 1; i < N; i++){
if (input[i] != 0) {
ans += ans[input[i] - 1];
}
else {
vector<bool> letters(26, false);
int prev = input[i - 1];
while (prev > 0) {
letters[ans[prev] - 48] = true;
prev = input[prev - 1];
}
next = letter + 1;
while (letters[(next) - 48]) {
next++;
}
ans += next;
}
}
cout << ans;
}