2019牛客暑期多校训练营(第七场)A String(暴力)
生活随笔
收集整理的這篇文章主要介紹了
2019牛客暑期多校训练营(第七场)A String(暴力)
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
鏈接:https://ac.nowcoder.com/acm/contest/887/A
來(lái)源:牛客網(wǎng)
題目描述
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輸入
復(fù)制 4 0 0001 0010 111011110輸出
復(fù)制 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 longint 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; }?
轉(zhuǎn)載于:https://www.cnblogs.com/RootVount/p/11355976.html
總結(jié)
以上是生活随笔為你收集整理的2019牛客暑期多校训练营(第七场)A String(暴力)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: spring中bean的两种注入方式
- 下一篇: HDU - 6641 TDL(数学)