UVA 1584 字符串

时间:2023-03-10 02:43:37
UVA 1584 字符串

VJ 该题 链接  https://vjudge.net/problem/UVA-1584

AC代码   字典序最小输出

 #include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
using namespace std;
const int maxn= ;
const int inf = 0x3f3f3f3f;
typedef long long ll;
char s[maxn];
int compare(char *s,int q,int p)
{
int n=strlen(s);
for(int i=;i<n;i++) //按字典序比较
{
if(s[(q+i)%n]!=s[(p+i)%n])
return s[(q+i)%n]<s[(p+i)%n];
}
return ; //相等
}
int main(int argc, char const *argv[])
{
int t;
cin>>t;
while(t--)
{
scanf("%s",s);
int ans=;
int len=strlen(s);
for(int i=;i<len;i++)
{
if(compare(s,i,ans))
ans=i;
}
for(int i=;i<len;i++)
{
printf("%c",s[(ans+i)%len]);
}
printf("\n");
}
return ;
}