CF1316B String Modification 题解 字符串模拟/找规律

题目链接:https://www.luogu.com.cn/problemnew/solution/CF1316B

解题思路完全照搬自 Andrewzdm 大神的博客:https://www.luogu.com.cn/blog/0408Dodgemin/cf1316b-ti-xie

实现代码如下:

#include <bits/stdc++.h>
using namespace std;
int T, n, k;
string s, t, ans;
int main() {
    cin >> T;
    while (T --) {
        cin >> n >> s;
        k = 0;
        for (int i = 1; i <= n; i ++) {
            string tmp = s.substr(0, i-1);
            if (i%2 == n%2) reverse(tmp.begin(), tmp.end());
            t = s.substr(i-1, n-i+1) + tmp;
            if (k == 0 || t < ans) {
                ans = t;
                k = i;
            }
        }
        cout << ans << endl << k << endl;
    }
    return 0;
}
原文地址:https://www.cnblogs.com/quanjun/p/12704062.html