题目:

B. Reversing Encryption
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

A string s

of length n

can be encrypted by the following algorithm:

  • iterate over all divisors of n
in decreasing order (i.e. from n to 1
), for each divisor d, reverse the substring s[1d] (i.e. the substring which starts at position 1 and ends at position d
  • ).

For example, the above algorithm applied to the string s

=" codeforces" leads to the following changes: " codeforces" " secrofedoc" " orcesfedoc" " rocesfedoc" " rocesfedoc" (obviously, the last reverse operation doesn't change the string because d=1

).

You are given the encrypted string t

. Your task is to decrypt this string, i.e., to find a string s such that the above algorithm results in string t. It can be proven that this string s

always exists and is unique.

Input

The first line of input consists of a single integer n

( 1n100) — the length of the string t. The second line of input consists of the string t. The length of t is n

, and it consists only of lowercase Latin letters.

Output

Print a string s

such that the above algorithm results in t

.

Examples
Input
Copy
10
rocesfedoc
Output
Copy
codeforces
Input
Copy
16
plmaetwoxesisiht
Output
Copy
thisisexampletwo
Input
Copy
1
z
Output
Copy
z
Note

The first example is described in the problem statement.

大体意思就是不停地对称,从第一个开始,隔一个,以当前的这个字符为对称轴,两边同时旋转,一直到中间停止。

一开始我是用char做的,打了打之后,发现对称的时候,两边的字符串得到长度必须相等才能对称,比如说 12345,你要以2为对称轴进行对称时,2的左边就很难弄,所以这个之后可以用string,string函数中还带有很多强大的库函数。

代码如下:

#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;
bool cmp(int t1,int t2){
return t1<t2;
}
int main(){
vector<int>wakaka;
int n;
cin>>n;
wakaka.clear();
string s;
cin>>s;
for(int i=1;i<=n;i++){
if(n%i==0){
wakaka.push_back(i);
}
}
sort(wakaka.begin(),wakaka.end(),cmp);
int len=wakaka.size();
for(int i=0;i<len;i++){
int t=wakaka[i];
reverse(s.begin(),s.begin()+t);//字符反转函数
}
cout<<s<<endl;
return 0;
}


Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐