CodeForces 746B Decoding
来源:互联网 发布:jsonp跨域原理 java 编辑:程序博客网 时间:2024/06/05 08:08
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.
Input:
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.
Output:Print the word that Polycarp encoded.
Example:
5logva
volga
2no
no
4abba
baba
Time limit : 1000MS
Memory limit : 262144KB
字符串模拟
#include<stdio.h>#include<string.h>int main(){ int n; char a[2005]; char b[2005]; while(scanf("%d",&n)!=EOF) { scanf("%s",a); int l = strlen(a); if(n%2==1) { for(int i=0,j=-1; i<l; i++) { if(i%2==0) b[(n+i-1)/2] = a[i]; else { j=j-2; b[(n+j)/2] = a[i]; } } for(int i=0; i<l; i++) printf("%c",b[i]); printf("\n"); } else if(n%2==0) { for(int i=0,j=-1; i<l; i++) { if(i%2==0) { b[(n+j)/2] = a[i]; j-=2; } else if(i%2==1) { b[(n+i)/2] = a[i]; } } for(int i=0; i<l; i++) printf("%c",b[i]); printf("\n"); } } return 0;}
Note:
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.
- CodeForces 746B Decoding
- 746 B. Decoding codeforces
- 【codeforces 746B】 Decoding
- CodeForces 746B Decoding
- 【Codeforces 746B Decoding】 + 构造
- codeforces 746 B. Decoding【水题】
- Codeforces #386 B 746B Decoding
- 【75.28%】【codeforces 764B】Decoding
- Codeforces Round #386 (Div. 2) 746B Decoding
- codeforces 746 Decoding
- 746B Decoding
- 【codeforces 747B】Mammoth's Genome Decoding
- CodeForces 747B Mammoth's Genome Decoding
- Codeforces Round #386 (Div. 2) B. Decoding
- Decoding CodeForces
- B. Decoding
- Codeforces Round #386(Div. 2)B. Decoding【模拟】
- 【58.33%】【codeforces 747B】Mammoth's Genome Decoding
- 欢迎使用CSDN-markdown编辑器
- 操作系统-内存管理机制
- 冒泡和捕获:事件代理
- UESTC1724 为了我们心爱的京电(欧拉函数)
- hdu-2846-Repository(字典树)
- CodeForces 746B Decoding
- 第三方登录集成步骤
- OpenCV学习笔记(5)——normalize函数
- css布局的小知识点积累(持续更)
- HashMap源码分析
- C/C++中volatile关键字详解
- (1)Tomcat的安装、基本使用方法、安装出现的问题、对网址(URL)的理解
- js 验证数字和字母组成的6-16位密码
- 理解函数原型的作用