Codeforces Round #490 (Div. 3) B

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

猜你喜欢

转载自www.cnblogs.com/lightgreenlemon/p/9211765.html