一.题目
长度为n的环状串有n种表示法,分别为从某
个位置开始顺时针得到。例如,图3-4的环状串
有10种表示:
CGAGTCAGCT,GAGTCAGCTC,AGTCAGCTCG等。在这些表示法中,字典序最小的称
为”最小表示”。
输入一个长度为n(n≤100)的环状DNA串(只包含A、C、G、T这4种字符)的一种表
示法,你的任务是输出该环状串的最小表示。例如,CTCC的最小表示是
CCCT,CGAGTCAGCT的最小表示为AGCTCGAGTC
二.思路
好像已经有strcmp,自带排序,就不用自己作函数了,有这个函数,整个题目就变得简单很多了。
三.代码
#include <stdio.h>
#include<string.h>
char temp[100000];
char target[100000];
int main ()
{
int n;
scanf("%d",&n);
scanf("%s",temp);
strcpy(target,temp);
int len=strlen(temp);
int i=0;
int j;
for(i=0;i<len;i++) //种数
{
char tem=temp[0]; //避免覆盖设置的tem临时字符
for(j=1;j<len;j++) //每一种的替换
{
temp[j-1] = temp[j];
}
temp[len-1] = tem; //实现替换
if(strcmp(temp,target)<0) {strcpy(target,temp);}
}
printf("%s",target);
return 0;
}