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 ...
随机推荐
- Download rtsp.c
1. [代码][C/C++]代码 /* * Copyright (c) 2011, Jim Hollinger * All rights reserved. * * Redistribution an ...
- Apache禁止或允许固定IP访问特定目录、文件、URL
1. 禁止访问某些文件/目录 增加Files选项来控制,比如要不允许访问 .inc 扩展名的文件,保护php类库: <Files ~ "\.inc$"> Order a ...
- 关于redis,学会这8点就够了
1,redis是什么 redis是一种支持Key-Value等多种数据结构的存储系统.可用于缓存,事件发布或订阅,高速队列等场景.该数据库使用ANSI C语言编写,支持网络,提供字符串,哈希,列表,队 ...
- 响应式web设计,html5和css3实战(@author Ben Fraim)
重定向 //请求重定向简化写法 response.sendRedirect("/day09/adv.html"); 转发 request.getRequestDispatcher( ...
- Idea无法加载主类
今天重装了下电脑,运行idea发现各种问题. 直接进主题哈, 遇到三种情况 第一种: 首先查看这里是否有多个,只保留当前需要用工程路径.点击P右边的删除即可 删除后 然后运行是否能运行. 如果没有的话 ...
- ng2自定义管道
一.管道的作用及本质 作用:数据处理 本质:公用的方法 二.定义管道组件 //summary.pipe.tsimport { Pipe, PipeTransform } from '@angular/ ...
- 报错:在做往下拉选里面拼接数据的时候 3个下拉选显示一个值 原因 @scope(单例)或者没配默认单例
解决 @scope(多例) 这是因为造成线程并发访问不安全
- RHEL6安装JDK7
一.安装准备 1.操作系统:redhat-server-6.1-x86_64 下载地址: http://www.verycd.com/files/d39b97540497d24175340915244 ...
- 【机器学习】迭代决策树GBRT(渐进梯度回归树)
一.决策树模型组合 单决策树C4.5由于功能太简单,并且非常容易出现过拟合的现象,于是引申出了许多变种决策树,就是将单决策树进行模型组合,形成多决策树,比较典型的就是迭代决策树GBRT和随机森林RF. ...
- 34.Docker安装Mysql参数及环境变量使用
容器安装好后,通过exec进去到容器的内部, 容器安装的时候两种容器配置参数 直接在镜像的后面加配置 第二种方式 把这段代码拷贝过来.参数我们可以写在镜像的后面 我们把参数写在镜像的后面 然后我们需要 ...