Codeforces Round #528-A. Right-Left Cipher(字符串模拟)
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard 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…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
Copy
ncteho
output
Copy
techno
input
Copy
erfdcoeocs
output
Copy
codeforces
input
Copy
z
output
Copy
z
分一下字符串的奇偶模拟即可,注意要用char 不要用string
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
char str[10005],str1[10005];
scanf("%s",str);
int len=strlen(str);
int s=0;
if(len%2==0) {
for(int t=len/2-1; t>=0; t--) {
str1[s++]=str[t];
str1[s++]=str[len-1-t];
}
} else {
str1[s++]=str[len/2];
for(int t=len/2-1; t>=0; t--) {
str1[s++]=str[len-1-t];
str1[s++]=str[t];
}
}
for(int t=0; t<s; t++) {
cout<<str1[t];
}
return 0;
}
Codeforces Round #528-A. Right-Left Cipher(字符串模拟)的更多相关文章
- Codeforces Round #528 (Div. 2)题解
Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...
- Codeforces Round #284 (Div. 2)A B C 模拟 数学
A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #285 (Div. 2) A B C 模拟 stl 拓扑排序
A. Contest time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- Codeforces Round #368 (Div. 2) B. Bakery (模拟)
Bakery 题目链接: http://codeforces.com/contest/707/problem/B Description Masha wants to open her own bak ...
- (AB)Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round
A. Right-Left Cipher time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #528 Solution
A. Right-Left Cipher Solved. 注意长度的奇偶 #include <bits/stdc++.h> using namespace std; string s; i ...
- Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round 4) C. Connect Three 【模拟】
传送门:http://codeforces.com/contest/1087/problem/C C. Connect Three time limit per test 1 second memor ...
- Codeforces Round #579 (Div. 3)D(字符串,思维)
#include<bits/stdc++.h>using namespace std;char s[200007],t[200007];int last[200007][27],nxt[2 ...
- Codeforces Round #272 (Div. 1)C(字符串DP)
C. Dreamoon and Strings time limit per test 1 second memory limit per test 256 megabytes input stand ...
随机推荐
- html5--2.9新的布局元素(6)-figure/figcaption
html5--2.9新的布局元素(6)-figure/figcaption 学习要点 了解figure/figcaption元素的语义和用法 通过实例理解figure/figcaption元素的用法 ...
- bzoj3513
给定n个长度分别为$a_i$的木棒,问随机选择3个木棒能够拼成三角形的概率. $a_i$和$n$都在$10^5$以内 对于每一个i,我们统计比i短的边有多少组合能组成长度<=i的 用1减去这个概 ...
- ACM学习历程—HDU 4726 Kia's Calculation( 贪心&&计数排序)
DescriptionDoctor Ghee is teaching Kia how to calculate the sum of two integers. But Kia is so carel ...
- ACM学习历程——UVA10112 Myacm Triangles(计算几何,多边形与点的包含关系)
Description Problem B: Myacm Triangles Problem B: Myacm Triangles Source file: triangle.{c, cpp, j ...
- poj3422K方格取数——最大费用最大流
题目:http://poj.org/problem?id=3422 最大费用最大流: 拆点,在自点之间连两条边,一条容量为1,边权为数字:一条容量为k-1,边权为0:表示可以走k次,只有一次能取到数字 ...
- Poj_1011_Sticks(剪枝)
一.Description 乔治拿来一组等长的木棒,将它们随机地砍断,使得每一节木棍的长度都不超过50个长度单位.然后他又想把这些木棍恢复到为裁截前的状态,但忘记了初始时有多少木棒以及木棒的初始长度. ...
- JSP介绍(2)--- 九大隐式对象
request对象 每当客户端请求一个JSP页面时,JSP引擎就会制造一个新的request对象来代表这个请求. request对象提供了一系列方法来获取HTTP头信息,cookies,HTTP方法等 ...
- 转:在Linux上安装ant环境
1.从http://ant.apache.org 上下载tar.gz版ant 2.复制到/usr下 3.tar -vxzf apahce-ant-1.9.2-bin.tar.gz 解压 4.chow ...
- ural 1500 Pass Licenses (状态压缩+dfs)
1500. Pass Licenses Time limit: 2.5 secondMemory limit: 64 MB A New Russian Kolyan believes that to ...
- linux 下定位程序假死
ps -ef | grep 程序名称 pstack 程序的进程ID