题意:给了一个长度为n的加密字符串,加密原理是:第一个字符一次,第二字符两次,第三个字符三次,第n个字n次。然后打印出原始字符串。
题解:根据加密规律,从下标0开始,每次用x记录当前下标前缀和,用空字符穿连接起来当前s[x]的字符就是答案。
A. Repeating 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 repeating.
Repeating cipher is used for strings. To encrypt the string s=s1s2…sms=s1s2…sm (1≤m≤101≤m≤10), Polycarp uses the following algorithm:
- he writes down s1s1 ones,
- he writes down s2s2 twice,
- he writes down s3s3 three times,
- ...
- he writes down smsm mm times.
For example, if ss="bab" the process is: "b" →→ "baa" →→ "baabbb". So the encrypted ss="bab" is "baabbb".
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 first line contains integer nn (1≤n≤551≤n≤55) — the length of the encrypted string. The second 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 exactly nn.
It is guaranteed that the answer to the test exists.
Output
Print such string ss that after encryption it equals tt.
Examples
input
Copy
6 baabbb
output
Copy
bab
input
Copy
10 ooopppssss
output
Copy
oops
input
Copy
1 z
output
Copy
z
c++:
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s,ans;
int n,x=0;
cin>>n>>s;
for(int i=0;i<n;i++)
{
x+=i;
if(s[x]) ans+=s[x];
else break;
}
cout<<ans<<endl;
return 0;
}
python:
n=int(input());s=input()
ans="";x=0;i=0
while(i<n):
ans+=s[i]
x+=1
i+=x
print(ans)