CF1095A Repeating Cipher

题目描述

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=s1​s2​…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;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值