CodeForces - 999B Reversing Encryption
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[1…d] (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 (1≤n≤100 ) — the length of the string t. The second line of input consists of the string t. The length of tis n, and it consists only of lowercase Latin letters.
Output
Print a string s such that the above algorithm results in t.
Examples
10
rocesfedoc
codeforces
16
plmaetwoxesisiht
thisisexampletwo
1
z
z
Note
The first example is described in the problem statement.
题目的意思就是例子里面写的那样,已知这个字符串的长度为n,如果一个数d为它的因子,那么从1到d都要逆序(字符串从1开始计数),将所有的因子求出,依次进行逆序就可以了,但是要注意的是,这里是从最小的因子开始逆序。
#include <bits/stdc++.h>
using namespace std;
char s[105];
int main()
{
int n;
while(~scanf("%d",&n))
{
getchar();
scanf("%s",s);
for(int i = 1; i < n ; i ++)
{
if(n % i == 0)
{
for(int j = 0; j < i / 2; j ++)
{
char op = s[j];
s[j] = s[i - j - 1];
s[i-j -1 ] = op;
}
}
}
for(int i = 0; i <=(n -1)/2; i ++)
{
char op = s[i];
s[i] = s[n - i - 1];
s[n - i - 1] = op;
}
printf("%s",s);
printf("\n");
}
return 0;
}
CodeForces - 999B Reversing Encryption的更多相关文章
- CF 999B. Reversing Encryption【模拟/string reverse】
[链接]:CF [代码]: #include<bits/stdc++.h> #define PI acos(-1.0) #define pb push_back #define F fir ...
- Reversing Encryption(模拟水题)
A string ss of length nn can be encrypted(加密) by the following algorithm: iterate(迭代) over all divis ...
- CF999B Reversing Encryption 题解
Content 给一个长度为 \(n\) 的字符串 \(s\),执行以下操作: 降序遍历 \(n\) 的所有因子(从 \(n\) 到 \(1\)). 对于每一个因子 \(i\) 翻转字符串 \(s_{ ...
- Codeforces Round #490 (Div. 3)
感觉现在\(div3\)的题目也不错啊? 或许是我变辣鸡了吧....... 代码戳这里 A. Mishka and Contes 从两边去掉所有\(≤k\)的数,统计剩余个数即可 B. Reversi ...
- [Codeforces]Codeforces Round #490 (Div. 3)
Mishka and Contest #pragma comment(linker, "/STACK:102400000,102400000") #ifndef ONLINE_JU ...
- Codeforces 958C3 - Encryption (hard)
C3 - Encryption (hard) 思路: 记sum[i]表示0 - i 的和对 p 取模的值. 1.如果k * p > n,那么与C2的做法一致,O(k*p*n)复杂度低于1e8. ...
- Codeforces 958C3 - Encryption (hard) 区间dp+抽屉原理
转自:http://www.cnblogs.com/widsom/p/8863005.html 题目大意: 比起Encryption 中级版,把n的范围扩大到 500000,k,p范围都在100以内, ...
- Encryption (hard) CodeForces - 958C3 (树状数组)
大意: 给定序列$a$, 要求将$a$分成$k$个非空区间, 使得区间和模$p$的和最小, 要求输出最小值. $k$和$p$比较小, 直接暴力$dp$, 时间复杂度是$O(nklogp)$, 空间是$ ...
- Codeforces Gym 100015H Hidden Code 暴力
Hidden Code 题目连接: http://codeforces.com/gym/100015/attachments Description It's time to put your hac ...
随机推荐
- hdu 1203 转换的01包问题。。。。
俗话说的话 正难则反.,. 这个基本的思想都用不好的话 回家种田去吧. #include<cstdio> #include<string.h> #include<ios ...
- Apache ---- Solrl漏洞复现
Solr是一个独立的企业级搜索应用服务器,它对外提供类似于Web-service的API接口.用户可以通过http请求,向搜索引擎服务器提交一定格式的XML文件,生成索引:也可以通过Http Get操 ...
- mybatis查询foreach使用
1.mybatis传入map参数,map中包含list: List<FukaModel> fukaModels = price.getSchemaPrice().getFukaList() ...
- VBA if...elseif...else语句
一个If语句,后面可以跟一个或多个由布尔表达式组成的elseif语句,然后是一个默认的else语句,当所有条件变为false时执行else语句块. 语法 以下是VBScript中If...Elseif ...
- $.ajax()属性详解
$.ajax()方法详解 jquery中的ajax方法参数总是记不住,这里记录一下. 1.url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. 2.type: 要求为Strin ...
- Java 之 Map 接口
一.Map 接口概述 java.util.Map 接口专门用来存放键值对这种对象关系的对象. 下面比较一下 Collection 与 Map 的区别: Collection 中的集合,元素是孤立存在的 ...
- html5+css3 background-clip 技巧
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 【leetcode】610. Triangle Judgement
原题 A pupil Tim gets homework to identify whether three line segments could possibly form a triangle. ...
- dbm和发射功率得对照表
原文链接:https://blog.csdn.net/nicholas_dlut/article/details/80950163dBm mW 下面是dbm和发射功率得对照表. 基本上市面上所有的无线 ...
- Linux服务器TIME_WAIT进程的解决与原因
linux服务器上tcp有大量time_wait状态的解决方法和原因解释 毫无疑问,TCP中有关网络编程最不容易理解的是它的TIME_WAIT状态,TIME_WAIT状态存在于主动关闭socket连接 ...