Right-Left Cipher_Codeforces

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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值