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 ...
随机推荐
- gmpy安装使用方法
gmpy是一种C编码的Python扩展模块,提供对GMP(或MPIR)多精度算术库的访问.gmpy 1.17是1.x系列的最终版本,没有进一步的更新计划.所有进一步的开发都在2.x系列(也称为gmpy ...
- centos7搭建EFK日志分析系统
前言 EFK可能都不熟悉,实际上EFK是大名鼎鼎的日志系统ELK的一个变种 在没有分布式日志的时候,每次出问题了需要查询日志的时候,需要登录到Linux服务器,使用命令cat -n xxxx|grep ...
- C# DataContractJsonSerializer
DataContractJsonSerializer dataSerializer = new DataContractJsonSerializer(request.getBizContentClas ...
- hdu 1002 prime 模板
Constructing Roads Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- CentOS 系统下使用 yum 安装 Redis
本文主要介绍在 CentOS 7 系统下使用 yum 安装 Redis 的过程. 更改 yum 源 将 Centos 的 yum 源更换为国内的阿里云源. 首先备份你的原镜像文件,保证出错后可以恢复: ...
- React/动态绑定class
第一种 字符串拼接 <i className={["iconfont"+" "+item.icon]} ></i> 第二种 有判断条件的 ...
- flex 布局方式
开始啦 1. flex-direction 有关主轴的对齐方式 column 自上到下 row 自左到右 -->默认值 row-reverse 自右到左 column-reverse 自下到上 ...
- 如何使 JavaScript 更高效?
传统的 Web 页面不会包含很多脚本,至少不会太影响 Web 页面的性能.然而,Web 页面变得越来越像应用程序,脚本对其的影响也越来越大.随着越来越多的应用采用 Web 技术开发,脚本性能的提升就变 ...
- ASE19团队项目 beta阶段 model组 scrum5 记录
本次会议于12月6日,19时30分在微软北京西二号楼sky garden召开,持续20分钟. 与会人员:Jiyan He, Lei Chai, Linfeng Qi, Xueqing Wu, Kun ...
- Linux命令——umask、setuid、setgid、sticky bit、chmod、chown
umask 权限遮罩码,用于控制文件,文件夹的默认权限 文件默认权限: 666-umask 文件夹默认权限: 777-umask 管理员root: umask= ...