链接:https://ac.nowcoder.com/acm/contest/328/A
来源:牛客网
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 32768K,其他语言65536K
64bit IO Format: %lld
Rabbit得到了一个字符串,她的好朋友xxx可以给这个字符串施加一次魔法。
魔法可以选择字符串的任一位置,并将该位置后面的所有字符水平拼接到串首。
例如:对于字符串abcde,可以通过施加魔法得到cdeab。
如果xxx通过施加魔法将字符串的字典序变得严格比之前的小,那么他将拿走这一字符串。
Rabbit想知道自己的字符串会不会被xxx拿走。
第一行一个整数n,表示字符串的长度。
接下来一行一个长度为n的只由小写字母组成的字符串。
如果Rabbit的字符串会被xxx拿走,输出“YES”。
否则输出“NO”。
(不输出引号)
示例1
复制
5
cdeab
复制
YES
xxx可以把e之后的部分“ab”放到串首,得到abcde,字典序比cdeab小,故将拿走字符串。
示例2
复制
5
abcde
复制
NO
1≤n≤100000
字典序的说明:https://en.wikipedia.org/wiki/Alphabetical_order
#include
#include
Hidden Password
Time Limit: 2 Seconds Memory Limit: 65536 KB
Some time the programmers have very strange ways to hide their passwords. See for example how Billy "Hacker" Geits hide his password. Billy chooses a string S composed of small Latin letters with length L. Then he makes all L-1 one-letter left cyclic shifts of the string and takes as a password one prefix of the lexicographically first of the obtained strings (including S). For example let consider the string alabala. The cyclic one-letter left shifts (including the initial string) are:
alabala
labalaa
abalaal
balaala
alaalab
laalaba
aalabal
and lexicographically first of them is the string aalabal. The first letter of this string is in position 6 in the initial string (the positions in the string are counted from 0).
Write a program that for given string S finds the start position of the smallest lexicographically one-letter left cyclic shift of this string. If the smallest lexicographically left shift appears more than once then the program have to output the smallest initial position.
Your program has to be ready to solve more than one test case. The first line of the input file will contains only the number T of the test cases. Each of the following T lines will describe one test case - first the length L of the string (5 <= L <= 100000) and then, separated by one space, the string S itself.
The output file have to contain exactly T lines with a single number each - the initial position found by your program.
Sample Input
2
6 baabaa
7 alabala
Sample Output
1
6
Source: Southeastern Europe 2003
Submit Status
#include
#include