time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Polycarp loves ciphers. He has invented his own cipher called Right-Left.
Right-Left cipher is used for strings. To encrypt the string s=s1s2…sn Polycarp uses the following algorithm:
he writes down s1,
he appends the current word with s2 (i.e. writes down s2 to the right of the current result),
he prepends the current word with s3 (i.e. writes down s3 to the left of the current result),
he appends the current word with s4 (i.e. writes down s4 to the right of the current result),
he prepends the current word with s5 (i.e. writes down s5 to the left of the current result),
and so on for each position until the end of s.
For example, if s=“techno” the process is: “t” → “te” → “cte” → “cteh” → “ncteh” → “ncteho”. So the encrypted s=“techno” is “ncteho”.
Given string t — the result of encryption of some string s. Your task is to decrypt it, i.e. find the string s.
Input
The only line of the input contains t — the result of encryption of some string s. It contains only lowercase Latin letters. The length of t is between 1 and 50, inclusive.
Output
Print such string s that after encryption it equals t.
Examples
inputCopy
ncteho
outputCopy
techno
inputCopy
erfdcoeocs
outputCopy
codeforces
inputCopy
z
outputCopy
z
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
char str[60];
int main() {
while (cin >> str) {
int len = strlen(str);
// int ans = len - 1;
// for (int i = 0, j = len - 1; i <= j; i++, j--) {
// str2[ans--] = str1[j]; str2[ans--] = str1[i];
// }
// printf ("%s\n", str2);
int start;
if (len % 2 == 0) start = len / 2 - 1;
else start = len / 2;
int right = start, left = start + 1;
for (int i = 1; i <= len; i++) {
if (i % 2 == 1) cout << str[right--];
else cout << str[left++];
}
cout << endl;
}
return 0;
}