Processing math: 0%

Thứ Bảy, 5 tháng 1, 2019

Codeforces Round #529 (Div.3) - Bài 1

Polycarp loves ciphers. He has invented his own cipher called repeating.
Repeating cipher is used for strings. To encrypt the string s=s_1s_2...s_m(1\le m\le 10), Polycarp uses the following algorithm:
+ he writes down s_1 ones,
+ he writes down s_2 twices,
+ he writes down s_3 three times,
+...
+ he writes down s_m m times.
For example, if s="bab" the process is: "b"\to "baa"\to "baabbb". So the encrypted s="bab" is "baabbb".
Given string t- the result of encryption of some string s. Your task is to decrypt it, i.e find the string s.
Input
The first line contains integer n(1\le n\le 55)- the length of the encrypted string. The second line of the input contains t- the result of encryption of some string s. It contains only lowercase Latin letters. The length of t is exactly n.
It is guarantee that the answer to the test exists.
Output
Print such string s that after encryption it equals t.
Examples
input
Copy
6
baabbb
output
Copy
bab
input
Copy
10
ooopppssss
output
Copy
oops
input
Copy
1
z
output
Copy
z
 Solution:
#include<bits/stdc++.h>
using namespace std;
int m;
int main(){
   int n;
   string s;
   cin>>s;
   cin>>s;
   for(int i=0;i<s.size();i+=m){
      cout<<s[i];
      m++;
   }
   return 0;
}

Không có nhận xét nào:

Đăng nhận xét

Bài G - Educatioal Round 62

Đề bài: Bạn được cho 1 đồ thị vô hướng đặc biệt. Nó bao gồm 2n đỉnh được đánh số từ 1 đến 2n. Dưới đây là một số đặc tính của đồ thị: + ...