A. Right-Left Cipher
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…sns=s1s2…sn Polycarp uses the following algorithm:
- he writes down s1s1,
- he appends the current word with s2s2 (i.e. writes down s2s2 to the right of the current result),
- he prepends the current word with s3s3 (i.e. writes down s3s3 to the left of the current result),
- he appends the current word with s4s4 (i.e. writes down s4s4 to the right of the current result),
- he prepends the current word with s5s5 (i.e. writes down s5s5 to the left of the current result),
- and so on for each position until the end of ss.
For example, if ss="techno" the process is: "t" →→ "te" →→ "cte" →→ "cteh" →→ "ncteh" →→ "ncteho". So the encrypted ss="techno" is "ncteho".
Given string tt — the result of encryption of some string ss. Your task is to decrypt it, i.e. find the string ss.
Input
The only line of the input contains tt — the result of encryption of some string ss. It contains only lowercase Latin letters. The length of tt is between 11 and 5050, inclusive.
Output
Print such string ss that after encryption it equals tt.
Examples
input
ncteho
output
techno
input
erfdcoeocs
output
codeforces
input
z
output
z
题意:字符串加密(或者说是解密),例如将字符串“abcdeh”进行加密,加密步骤依次为:
c
cd
cdb
cdbe
cdbea
cdbeah
即从字符串中间的第一个字符开始,从右往左输出字符 。
代码:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define mem(a,b) memset(a,b,sizeof(a))
#define closeio std::ios::sync_with_stdio(false)
int main()
{
string a;
int n,i,l,r;
cin>>a;
n=a.length();
if(n%2==0)
l=r=n/2-1;
else
l=r=n/2;
while(1)
{
if(l==r)
cout<<a[l];
else
{
if(r<n)
cout<<a[r];
if(l>=0)
cout<<a[l];
}
l--;
r++;
if(r>=n)
break;
}
cout<<endl;
return 0;
}