-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDecoding.cpp
47 lines (43 loc) · 1.43 KB
/
Decoding.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
/*
Polycarp is mad about coding, that is why he writes Sveta encoded messages.
He calls the median letter in a word the letter which is in the middle of the word.
If the word's length is even, the median letter is the left of the two middle letters.
In the following examples, the median letter is highlighted: contest, info.
If the word consists of single letter, then according to above definition this letter is the median letter.
Polycarp encodes each word in the following way: he writes down the median letter of the word,
then deletes it and repeats the process until there are no letters left. For example,
he encodes the word volga as logva.
You are given an encoding s of some word, your task is to decode it.
*/
#include<bits/stdc++.h>
using namespace std;
int main(void){
int n, flag = 0;
string str, res;
cin >> n >> str;
if(n % 2 != 0){
for(int i = 0; i < str.length(); i++){
if(flag == 0){
res.push_back(str[i]);
flag = 1;
}
else{
res.insert(res.begin(), str[i]);
flag = 0;
}
}
}
else{
for(int i = 0; i < str.length(); i++){
if(flag == 0){
res.insert(res.begin(), str[i]);
flag = 1;
}
else{
res.push_back(str[i]);
flag = 0;
}
}
}
cout << res << endl;
}