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 ...
随机推荐
- PyQt5豆瓣镜像下快速安装
直接pip安装,慢到你怀疑人生.豆瓣镜像安装,嗯,不能更爽. pip install PyQt5 -i https://pypi.douban.com/simple 谢谢:https://blog.c ...
- listen 80
Facebook Quietly Created New Email Addresses For a company that made its name by building one of the ...
- C语言中mktime函数功能及用法
今天联系写一个日历的程序,需要算出月份中的第一天是星期几,用到了mktime()这个函数,感觉这个函数挺有用的,分享给大家. 原型:time_t mktime(struct tm *) 其中的tm结构 ...
- Posix线程编程指南(1)
这是一个关于Posix线程编程的专栏.作者在阐明概念的基础上,将向您详细讲述Posix线程库API.本文是第一篇将向您讲述线程的创建与取消. 一.线程创建 1.1 线程与进程相对进程而言,线程是一 ...
- P1880 [NOI1995]石子合并[区间dp+四边形不等式优化]
P1880 [NOI1995]石子合并 丢个地址就跑(关于四边形不等式复杂度是n方的证明) 嗯所以这题利用决策的单调性来减少k断点的枚举次数.具体看lyd书.这部分很生疏,但是我还是选择先不管了. # ...
- 关于redis,学会这8点就够了
1,redis是什么 redis是一种支持Key-Value等多种数据结构的存储系统.可用于缓存,事件发布或订阅,高速队列等场景.该数据库使用ANSI C语言编写,支持网络,提供字符串,哈希,列表,队 ...
- [原创]如何解决IE10下CkEditor报 --- SCRIPT5007: 无法获取未定义或 null 引用的属性“toLowerCase”
如何解决IE10下CkEditor报 --- SCRIPT5007: 无法获取未定义或 null 引用的属性“toLowerCase” 错误 如果你的IE是IE10,且不是运行在IE的兼容模式你也许会 ...
- syslog-ng 配置(tcp协议)
一.概况 两台服务器,都安装syslog-ng,一台服务端,一台客户端: server:192.168.209.19 client:192.168.209.18 二.安装 采用yum安装,执行: yu ...
- bzoj4763
$分块$ $一个很有趣的技巧$ $在树上选sqrt(n)个关键点,每两个关键点之间的距离<=sqrt(n),每个关键点属于一条链$ $预处理出每两个关键点的bitset$ $每次询问就暴力向上爬 ...
- 【旧文章搬运】VC插件中如何获取当前工程的工作目录
原文发表于百度空间,2014-09-24========================================================================== 好难找的资 ...