链接:https://ac.nowcoder.com/acm/contest/887/A来源:牛客网
题目描述
A string is perfect if it has the smallest lexicographical ordering among its cyclic rotations.
For example: "0101" is perfect as it is the smallest string among ("0101", "1010", "0101", "1010").
Given a 01 string, you need to split it into the least parts and all parts are perfect.
输入描述:
The first line of the input gives the number of test cases,
T (T≤300)T\ (T \leq 300)T (T≤300). test cases follow.For each test case, the only line contains one non-empty 01 string. The length of string is not exceed 200.
输出描述:
For each test case, output one string separated by a space.
示例1
输入
复制
4
0
0001
0010
111011110
输出
复制
0
0001
001 0
111 01111 0
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
#define MAXN 100010
#define ll long long
int t;
string s;
bool minma(
string x)
{
int len =
x.size();
for(
int i =
1; i < len; i++
)
for(
int j =
0; j < len; j++
)
{
if(x[j] < x[(j + i) %
len])
break;
else if(x[j] > x[(j + i) %
len])
return false;
}
return true;
}
int main()
{
cin>>
t;
while(t--
)
{
cin>>
s;
int len =
s.size();
int i =
0;
while(i <
len)
{
for(
int j = len - i; j >
0; j--
)
{
if(minma(s.substr(i, j)))
{
cout<<
s.substr(i, j);
i +=
j;
if(i <
len)
printf(" ");
break;
}
}
}
printf("\n");
}
return 0;
}
转载于:https://www.cnblogs.com/RootVount/p/11355976.html