[CF1316B] String Modification

Solution

Essentially the entire string left a number of bits, the extra portion moved to the right, and a parity inverting

#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;
    }
}

Guess you like

Origin www.cnblogs.com/mollnn/p/12460174.html