zoukankan      html  css  js  c++  java
  • 2019牛客暑期多校训练营(第七场)A String(暴力)

    链接: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 (T300).  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("
    ");
        }
        return 0;
    }
  • 相关阅读:
    060821流水账
    060721流水账
    060421流水账
    [Tips] 更新oh my zsh
    [Tips] updraftplus备份wordpress
    [Tips] SSH免密登陆
    [Notes] 基于阿里云的SSL在容器化wordpress中部署https服务
    [Tips] wordpress添加文章计数
    [Notes] 容器化部署wordpress
    [Notes] pandas 保存hdf5时numpy array遇到的性能warning
  • 原文地址:https://www.cnblogs.com/RootVount/p/11355976.html
Copyright © 2011-2022 走看看