B. Decoding
来源:互联网 发布:benchmark测试软件 编辑:程序博客网 时间:2024/05/18 03:27
Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, info. If the word consists of single letter, then according to above definition this letter is the median letter.
Polycarp encodes each word in the following way: he writes down the median letter of the word, then deletes it and repeats the process until there are no letters left. For example, he encodes the word volga as logva.
You are given an encoding s of some word, your task is to decode it.
The first line contains a positive integer n (1 ≤ n ≤ 2000) — the length of the encoded word.
The second line contains the string s of length n consisting of lowercase English letters — the encoding.
Print the word that Polycarp encoded.
5logva
volga
2no
no
4abba
baba
In the first example Polycarp encoded the word volga. At first, he wrote down the letter l from the position 3, after that his word looked like voga. After that Polycarp wrote down the letter o from the position 2, his word became vga. Then Polycarp wrote down the letter g which was at the second position, the word became va. Then he wrote down the letter v, then the letter a. Thus, the encoding looked like logva.
In the second example Polycarp encoded the word no. He wrote down the letter n, the word became o, and he wrote down the letter o. Thus, in this example, the word and its encoding are the same.
In the third example Polycarp encoded the word baba. At first, he wrote down the letter a, which was at the position 2, after that the word looked like bba. Then he wrote down the letter b, which was at the position 2, his word looked like ba. After that he wrote down the letter b, which was at the position 1, the word looked like a, and he wrote down that letter a. Thus, the encoding is abba.
解题说明:本题是一道字符串题,可以从简单例子着手,通过逆向思维进行推理得出原来的字符串。
#include<cstdio>#include <cstring>#include<cmath>#include<iostream>#include<algorithm>#include<vector>#include <map>using namespace std;int main(){int n,i;cin>>n;string median;cin>>median;string ans;for(i=n;i>0;i--){if(i%2){ans=ans+median[n-i];}else{ans=median[n-i]+ans;}}cout<<ans<<endl;return 0;}
- B. Decoding
- CodeForces 746B Decoding
- 746 B. Decoding codeforces
- 746B Decoding
- 【codeforces 746B】 Decoding
- CodeForces 746B Decoding
- 【75.28%】【codeforces 764B】Decoding
- 【Codeforces 746B Decoding】 + 构造
- codeforces 746 B. Decoding【水题】
- Codeforces #386 B 746B Decoding
- 747B Mammoth's Genome Decoding
- 【codeforces 747B】Mammoth's Genome Decoding
- CodeForces 747B Mammoth's Genome Decoding
- Codeforces Round #386 (Div. 2) B. Decoding
- Codeforces Round #386(Div. 2)B. Decoding【模拟】
- 【58.33%】【codeforces 747B】Mammoth's Genome Decoding
- Codeforces 747B Mammoth's Genome Decoding(碱基对)
- 【Codeforces 747B Mammoth's Genome Decoding】+ 构造
- ViewPager初步用法(二)
- 五、Linux快速体验
- 六、Linux命令详解
- 9.无序数组——迭代顺序查找(迭代)
- Java 产生0-10000的随机数 并写入TXT文档中
- B. Decoding
- 七、Linux文本编辑器
- 两种新型的图片格式 : SVG和WebP的比较
- 八、Linux网络配置
- 九、Linux远程登陆
- OpenCV入门教程(6)-Mat类之内存管理和输出
- 十、Windows与Linux文件互享
- tomcat启动时闪退
- 欢迎使用CSDN-markdown编辑器