[CF1316B] String Modification

Solution

实质上就是整个字符串左移若干位,多出来的部分挪到右边,并根据奇偶翻转

#include <bits/stdc++.h>
using namespace std;

int T,n;
string str;

signed main() {
    ios::sync_with_stdio(false);
    cin>>T;
    while(T--) {
        cin>>n>>str;
        string mx=str;
        int k=1;
        for(int i=1;i<n;i++) {
            string tmp;
            for(int j=i;j<str.length();j++) tmp+=str[j];
            if((n-i)%2==1) for(int j=i-1;j>=0;--j) tmp+=str[j];
            else for(int j=0;j<i;j++) tmp+=str[j];
            if(tmp<mx) mx=tmp,k=i+1;
        }
        cout<<mx<<endl<<k<<endl;
    }
}
原文地址:https://www.cnblogs.com/mollnn/p/12460174.html