-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathb.cpp
35 lines (32 loc) · 790 Bytes
/
b.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <bits/stdc++.h>
using namespace std;
string op(string s, int k){
if(k == s.length()){
reverse(s.begin(), s.end());
return s;
}
string start = s.substr(k - 1), other = s.substr(0, k - 1);
if(k % 2 == s.length() % 2){
reverse(other.begin(), other.end());
}
return start + other;
}
int main(){
int T; cin >> T;
for(int tc = 0; tc < T; tc++){
int N;
string s;
cin >> N >> s;
string optstring = s;
int optk = 1;
for(int i = 2; i <= N; i++){
string oped = op(s, i);
if(optstring.compare(oped) > 0){
optstring = oped;
optk = i;
}
}
cout << optstring << endl << optk << endl;
}
return 0;
}