题目描述
Polycarp loves ciphers. He has invented his own cipher called repeating.
Repeating cipher is used for strings. To encrypt the string s=s1s2…sm s=s_{1}s_{2} \dots s_{m} s=s1s2…sm ( 1≤m≤10 1 \le m \le 10 1≤m≤10 ), Polycarp uses the following algorithm:
- he writes down s1 s_1 s1 ones,
- he writes down s2 s_2 s2 twice,
- he writes down s3 s_3 s3 three times,
- ...
- he writes down sm s_m sm m m m times.
For example, if s s s ="bab" the process is: "b" → \to → "baa" → \to → "baabbb". So the encrypted s s s ="bab" is "baabbb".
Given string t t t — the result of encryption of some string s s s . Your task is to decrypt it, i. e. find the string s s s .
输入格式:
The first line contains integer n n n ( 1≤n≤55 1 \le n \le 55 1≤n≤55 ) — the length of the encrypted string. The second line of the input contains t t t — the result of encryption of some string s s s . It contains only lowercase Latin letters. The length of t t t is exactly n n n .
It is guaranteed that the answer to the test exists.
输出格式:
Print such string s s s that after encryption it equals t t t .
输入输出样例
输入样例#1: |
6 baabbb |
输出样例#1: |
bab |
输入样例#2: |
10 ooopppssss |
输出样例#2: |
oops |
输入样例#3: |
1 z |
输出样例#3: |
z |
题意:
现在有一个字符串s,然后将s1写1遍,然后将s2写2遍,然后将s3写3遍。然后将sn写n遍,得到一个字符串s′
for example: bab->写一遍s1(就是b)->写两遍s2(就是aa)->写三遍s3(就是bbb)->得到s′(就是baabbb)
输入格式:第一行输入一个数n(1≤n≤55),表示字符串s的长度 第二行输入字符串s′(注意输入的是s′,这是一个解密过程)
输出格式:一行,字符串s
代码:
#include<cstdio>
using namespace std;
int i=0,l,n=0;
char s[60];
int main(){
scanf("%d%s",&l,s);
for(;i<l;i+=n+1,n++) printf("%c",s[i]);
return 0;
}