问题:算法竞赛入门经典(第二版)例题3-6 环状序列(Circular Sequence,ACM/ICPC Seoul 2004,UVA1584)
题目:长度为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;
}
感觉结果没错但还是WA
求指点错误
-