题目:长度为n的环形串有n种表示法,分别为从某个位置开始顺时针得到。在这些表示法中,字典序最小的称为“最小表示”。
输入一个长度为n的环形串,你的任务是输出该环形串的最小表示。
例如,CGAGTCAGCT的最小表示为AGCTCGAGTC。
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define max 201
char s[max],x[max],mi[max];
int main()
{
int t;
cin >> t;
int m = 0, p=0;
while (t--)
{
memset(x, 0, 201);
memset(mi, 0, 201);
cin >> s;
int n = strlen(s);
strcpy(mi, s);
strcpy(x, s);
for (int i = 0; i < n; i++)
{
x[n + i] = x[i];
if (m = strcmp(mi, x + 1 + i) == 1) {
strcpy(mi, x + i + 1);
}
}
cout << mi << endl;
}
return 0;
}
-
原题呢,你只放自己的解读,根据你自己的解读看输出当然怎么看怎么对,你要回归原题,看到底怎么要求的