码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #490 (Div. 3) B

时间:2018-06-22 10:16:27      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:ons   ios   max   nbsp   cout   turn   ring   长度   ret   

传送门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

标签:ons   ios   max   nbsp   cout   turn   ring   长度   ret   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!