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 ...
随机推荐
- java——多态例题
class A { public String show(D obj) { return ("A and D"); } public String show(A obj) { re ...
- sysbench安装和测试
1.首先安装依赖 yum install mariadb-devel yum install automake libtool –y 2.下载安装包 wget https://github.com/a ...
- IDEA如何本机调试springboot应用打的jar包
背景: 我用命名行 执行 java -jar ***.jar发现 springboot启动时抛出错误,因此想debug进去看看究竟为什么出错. 1 在命令行执行 java -jar -Xdebug ...
- 冒泡(bubblesort)、选择排序、插入排序、快速排序
冒泡排序(bubblesort) 特点:通过换位置的方式,一直向上冒泡 package main import "fmt" func bubbleSortAsc(arrayA [] ...
- 对WAF的一些认知
WAF分为非嵌入型与嵌入型, 非嵌入型指的是硬WAF.云WAF.虚拟机WAF之类的:嵌入型指的是web容器模块类型WAF.代码层WAF.非嵌入型对WEB流量的解析完全是靠自身的,而嵌入型的WAF拿到的 ...
- Sharing is only supported for boot loader classes because bootstrap classpath has been appended
在idea里面运行项目,terminal里面报“Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boo ...
- jeffy-vim-v2.9
http://pan.baidu.com/s/1qW1DlP6
- 排序算法(冒泡、选择)-python代码展示
冒泡排序: def bubble_sort(list): for i in range(len(list) - 1): # 这个循环负责设置冒泡排序进行的次数 for j in range(len(l ...
- editplus多行合并成一行
原文:https://www.cnblogs.com/jpfss/p/9238877.html Editplus 合并行快捷键: Ctrl+Shift+J ,选中要合并的行,再按快捷键即可
- Python 文件操作(2)
上一篇学习了用内置函数 open() 来打开文件,并且用 f.close() 来关闭文件. 今天来学习对这个文件对象的其他操作:读.写.找到文件当前位置-- 1.读取文件 三种方法: read([si ...