codeforces 999B Reversing Encryption

http://www.elijahqi.win/archives/3817
题目描述
A string

s

s of length

n

n can be encrypted by the following algorithm:

iterate over all divisors of
n

n in decreasing order (i.e. from n

n to 1

1 ),
for each divisor
d

d , reverse the substring s[1 \dots d]

s[1…d] (i.e. the substring which starts at position 1

1 and ends at position d

d ).
For example, the above algorithm applied to the string

s

s =”codeforces” leads to the following changes: “codeforces”

\to

→ “secrofedoc”

\to

→ “orcesfedoc”

\to

→ “rocesfedoc”

\to

→ “rocesfedoc” (obviously, the last reverse operation doesn’t change the string because

d=1

d=1 ).

You are given the encrypted string

t

t . Your task is to decrypt this string, i.e., to find a string

s

s such that the above algorithm results in string

t

t . It can be proven that this string

s

s always exists and is unique.

输入输出格式
输入格式:

The first line of input consists of a single integer

n

n (

1 \le n \le 100

1≤n≤100 ) — the length of the string

t

t . The second line of input consists of the string

t

t . The length of

t

t is

n

n , and it consists only of lowercase Latin letters.

输出格式:

Print a string

s

s such that the above algorithm results in

t

t .

输入输出样例
输入样例#1: 复制

10
rocesfedoc
输出样例#1: 复制

codeforces
输入样例#2: 复制

16
plmaetwoxesisiht
输出样例#2: 复制

thisisexampletwo
输入样例#3: 复制

1
z
输出样例#3: 复制

z
说明
The first example is described in the problem statement.

reverse 末端指针+1

#include<bits/stdc++.h>
using namespace std;
char s[110];
int main(){
//  freopen("b.in","r",stdin);
    int n;scanf("%d",&n);
    scanf("%s",s+1);
    for (int i=1;i<=n;++i){
        if (n%i) continue;
        reverse(s+1,s+i+1);
    }
    printf("%s",s+1);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值