Sicily 1860. BOB or BBO
来源:互联网 发布:openwrt python mini 编辑:程序博客网 时间:2024/05/05 21:29
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
1BOB
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;}
- Sicily 1860. BOB or BBO
- Sicily 1798. Alice and Bob
- sicily--1798. Alice and Bob
- sicily 1798.Aclie and Bob
- Sicily 1798. Alice and Bob
- Sicily 1732. Alice and Bob
- Sicily 13289. Alice and Bob
- Sicily 2683. Alice and Bob
- Sicily 1798. Alice and Bob
- Sicily 1732 Alice and Bob (二进制数的最大公约数)
- Sicily 1003. Hit or Miss
- sicily--1003. Hit or Miss
- sicily 1003 Hit or Miss
- sicily 1003. Hit or Miss
- Sicily 1003. Hit or Miss
- sicily 1003. Hit or Miss
- Sicily 1944. Exists? Or not
- Sicily 1003. Hit or Miss
- Sicily 1828. Minimal
- Linux--查看文件夹磁盘大小命令
- 2分钟快速开发之代码生成器 asp.net mvc4+easyui+knockoutjs
- 不使用系统自带的button
- Win8.1下Cocos2d-x 3.2 命令行编译apk
- Sicily 1860. BOB or BBO
- EOS单向1对N关联GOOD
- IOS学习 iOS编程修改系统音量
- C#dll的生成和调用
- 1、判断一个数是否为素数,并求出1-1000中的全部素数(素数即质数,除1和自身以外没有其它因子,最小的质数是2)。
- Java中&&与&以及|| 与|的区别和位操作
- meminfo vmstat procrank top等详解
- Sicily 1822. Fight Club
- 电商页面设计 只需懂六个字