Right-Left Cipher Codeforces Round #528 (Div. 2-A

题面:

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

中文的意思就 是 将一个字符串 按照一个 规则来加密,就是 右-左 的规则,意思就是,原字符串的第二位是右,不动,下一位就该轮到左了,就把这个字符拿到字符串的最前面,然后继续右-左 来安排各个字符 的位置。

图解:

而本题 是让你解密 ,输如加密后的字符串,输出解密后的 字符串。

代码:

#include<stdio.h>
#include<iostream>
using namespace std;
#include<string.h>
#include<stdlib.h>
const int maxn=105;
int main()
{
	int num;
	int i;
	int j=0;
	char b[maxn];
	char c[maxn];
	int len;
	char a[maxn];
	gets(a);
	len=strlen(a);
	if(len==2||len==1)
		cout<<a;
	else
	{
		if(len%2==0)
			num=len/2-1;
		else
			num=(len+1)/2-1;
		for(i=0;i<num;i++)
			b[j++]=a[i];
		b[j]=0;
		j=0;
		for(;a[i];i++)
			c[j++]=a[i];
		c[j]=0;	
		int len1=strlen(b);
		int len2=strlen(c);
		int z=len1-1;
		int l=0;
		j=1;
		cout<<c[0];
		int m=1;
		while(l<(len1+len2-1))
		{
			if(m==0)
			{
				m=!m;
				cout<<b[z--];
			}
			else
			{
				m=!m;
				cout<<c[j++];
			}
			l++;
		}
	}
	return 0;
}

我的解题思路是,如果字符串 的数量小于3的时候,根本就不用换 ,直接输出字符串就可以。而如果大于等于3的时候,这时就会移动某些字符,我先找到原来字符串第一个字符的位置,如果字符串位数 是奇数,原字符串第一个字符 下表就是 (len+1)/2-1, 如果是 偶数的话,那就是(len)/2;  将 首字符 两边的 字符都 各自放到一个 字符数组中 。接下来,就是 如何 合并两个数组,来恢复 原字符串。首先  先输出 那个 固定的(不参与右-左)的字符,接下来 我1 和 0来模拟 是否 该输出 是 左 的字符,如果是 0,就倒序输出(因为是倒序移动到前面的)首字符前面的,否则 就 输出 是右 的 字符。这里 每输出一位字符,就用计数器L计入,当L大于两个字 符数组 长度的总和,就结束。  

猜你喜欢

转载自blog.csdn.net/tsam123/article/details/85228240