forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzigzag.cpp
55 lines (46 loc) · 927 Bytes
/
zigzag.cpp
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
48
49
50
51
52
53
54
55
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if(n <= 25) {
cout << "a";
cout << (char)('a'+n) << endl;
return 0;
}
string s = "a";
if(n % 25 == 0) {
while(n >= 25) {
n -= 25;
if(s[s.size()-1] == 'a') {
s.push_back('z');
}
else {
s.push_back('a');
}
}
cout << s << endl;
return 0;
}
int rem = n % 25;
bool secondrem = rem%2==1;
s += 'n' + rem/2;
while(n >= 25) {
n -= 25;
if(s[s.size()-1] == 'a') {
s.push_back('z');
}
else {
s.push_back('a');
}
}
if(!secondrem) {
if(s[s.size()-1] == 'a') {
s[s.size()-1]++;
}
else {
s[s.size()-1]--;
}
}
cout << s << endl;
}