【CF 1087A】Right-Left Cipher

                                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;
}

 

全部评论

相关推荐

我也不知道起什么名字...:我感觉刷到8-10遍就悟了,之前特别难懂的题,现在就很自然的感觉不就这样的吗。比如链表排序,两个有序数组求中位数,背包问题等
牛客激励计划
点赞 评论 收藏
分享
08-27 12:02
已编辑
南京外国语学校 网络安全
再来一遍:实则劝各位不要all in华子,不要相信华为hr
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务