1. 程式人生 > >UVa1584 Circular Sequence 環狀序列

UVa1584 Circular Sequence 環狀序列

有點水
AC程式碼

#include <cstdio>
#include <cmath>
#include <cstring>
int main()
{
	int T, i, j;
	char gene[101], seq[101][101], ans[101];
	int n;
	scanf("%d", &T);
	while (T--)
	{
		scanf("%s", gene);
		n = strlen(gene);
		int k = 0;
		for (i = 0; i < n; i++)
		{
			for (j = 0; j < n;
j++) seq[i][j] = gene[(j + i) % n]; seq[i][n] = '\0'; } strcpy(ans, gene); for (i = 0; i < n; i++) { if (strcmp(seq[i], ans)<0) strcpy(ans, seq[i]); } printf("%s\n", ans); } }