首页 > 其他 > 详细

Codeforces Round #490 (Div. 3) B

时间:2018-06-22 10:12:14      阅读:259      评论:0      收藏:0      [点我收藏+]

传送门http://codeforces.com/contest/999/problem/B

一个长度为n的字符串t,将n的因子从大到小排个序(设为a[i]),每次把t的第一个字符到第a[i]个字符reverse一下,最终得到一个怪异的串s。现在给n和s,求t。

最长100个字符,直接模拟好了。先把n分解质因数,然后进行“逆操作”,即把因子从小到大排序,然后把给的串reverse回去。

我在做的时候忘记reverse怎么用了,尴尬。

 1 #include <iostream>
 2 #include <string>
 3 #include <cstring>
 4 #include <algorithm>
 5 using namespace std;
 6 const int maxn = 110;
 7 int n, a[maxn], cnt;
 8 string t;
 9 int main()
10 {
11     cin >> n >> t;
12     for (int i = 1; i <= n; ++i)
13         if (n % i == 0)
14             a[++cnt] = i;
15     for (int i = 1; i <= cnt; ++i)
16         reverse(t.begin(), t.begin() + a[i]);
17     cout << t;
18     return 0;
19 }

 

Codeforces Round #490 (Div. 3) B

原文:https://www.cnblogs.com/lightgreenlemon/p/9211765.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!