标签:div i++ names 一个 思路 sam std its https
2
6 baabaa
7 alabala
1
6
思路:直接模拟的话会时间超限,所以先选出字符串中字典序最小的那个字符,然后不是这个字符开头的就直接跳过,优化一下就好了
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
int n;
string a;
int record;
while(t--)
{
string c="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
cin>>n>>a;
char MIN=‘z‘;
int l=a.length();
for(int i=0; i<l; i++)
{
MIN=min(MIN,a[i]);//先找出最小的字母
}
for(int i=0; i<l; i++)
{
if(a[i]==MIN)
{
string b=a.substr(i,n)+a.substr(0,i);//以最小字母开头的字符串
if(c>b)
{
c=b;
record=i;//记录最小字符串的第一个字符的原位置
}
}
}
cout<<record<<endl;
}
return 0;
}
转自:https://blog.csdn.net/qq_38135639/article/details/70880181
标签:div i++ names 一个 思路 sam std its https
原文地址:https://www.cnblogs.com/FantasticDoubleFish/p/14315136.html