Sicily 1860. BOB or BBO

本文深入探讨了AI音视频处理领域中的视频分割与语义识别技术,介绍了视频分割的基本概念、算法及其应用,并详细阐述了语义识别在智能视频分析中的重要作用,包括其在自动驾驶、AR增强现实等场景中的实际应用。

1860. BOB or BBO

Constraints

Time Limit: 1 secs, Memory Limit: 32 MB

Description

Definition 1:If string S=(S0S1S2…Sn),Ror(S)=(SnS0S1…Sn-1)
Definition 2:Ror0(S)=S,Rorn(S)=Ror(Rorn-1(S))
Definition 3:Pow(S)={Ror0(S),Ror1(S),…,Rorlen(S)-1(S)}
Now your task is to find the string T which has the smallest lexicographic order in Pow(S).
For example,S=BOB,Ror0(S)=BOB,Ror1(S)=BBO,Ror2(S)=OBB,Pow(S)={BOB,BBO,OBB}.
Obviously,T=BBO is the correct answer. 

Input

The first line of the input is a positive integer.It is the number of the test cases followed. Each test case contains a string S,which consists of capital letters.The length of string S isn’t larger than 10000. 

Output

The output of the program should consist of one line of output for each test case. The output of each test case only contains the string T. No any redundant spaces are needed. 

Sample Input

1
BOB

Sample Output

BBO

// Problem#: 1860
// Submission#: 3343303
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include <algorithm>
#include <iostream>
#include <string>
#include <stdio.h>
#include <queue>
#include <string.h>
#include <vector>
#include <iomanip>
#include <map>
#include <stack>
#include <functional>
#include <list>
#include <cmath>
using namespace std;

int main() {

    std::ios::sync_with_stdio(false);
    int caseNum;
    cin >> caseNum;

    while (caseNum--) {
        string s;
        cin >> s;
        int l = s.size();
        char minC = 'Z';
        for (int i = 0; i < l; i++) {
            if (minC > s[i]) {
                minC = s[i];
                if (minC == 'A') break;
            }
        }
        list<vector<int> > v;
        for (int i = 0; i < l; i++) {
            if (s[i] == minC) {
                v.push_back(vector<int>(1, i));
            }
        }

        int counter = 1;
        while (v.size() > 1 && counter < l && counter + v.size() <= l) {
            char minC = 'Z';
            for (list<vector<int> >::iterator iter = v.begin(); iter != v.end(); iter++) {
                int last = (*iter)[iter->size() - 1];
                int next = last + 1;
                if (next == l) next = 0;
                if (s[next] < minC) {
                    minC = s[next];
                    if (minC == 'A') break;
                }
            }
            for (list<vector<int> >::iterator iter = v.begin(); iter != v.end(); ) {
                int last = (*iter)[iter->size() - 1];
                int next = last + 1;
                if (next == l) next = 0;
                if (s[next] != minC) {
                    list<vector<int> >::iterator del = iter;
                    iter++;
                    v.erase(del);
                } else {
                    iter->push_back(next);
                    iter++;
                }
            }
            counter++;
        }

        string ans;
        int pos = (*(v.begin()))[0];
        for (int i = 0; i < l; i++) {
            ans.push_back(s[pos]);
            pos = pos + 1;
            if (pos == l) pos = 0;
        }
        cout << ans << endl;
        
    }


    //getchar();
    //getchar();
    
    return 0;
}                                 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值