​   Some DNA sequences exist in circular forms as in the following figure, which shows a circular sequence “CGAGTCAGCT”, that is, the last symbol “T” in “CGAGTCAGCT” is connected to the first symbol “C”. We always read a circular sequence in the clockwise direction.

​   Since it is not easy to store a circular sequence in a computer as it is, we decided to store it as a linear sequence. However, there can be many linear sequences that are obtained from a circular sequence by cutting any place of the circular sequence. Hence, we also decided to store the linear sequence that is lexicographically smallest among all linear sequences that can be obtained from a circular sequence.

​   Your task is to find the lexicographically smallest sequence from a given circular sequence. For the example in the figure, the lexicographically smallest sequence is “AGCTCGAGTC”. If there are two or more linear sequences that are lexicographically smallest, you are to find any one of them (in fact, they are the same).

Input

​   The input consists of T test cases. The number of test cases T is given on the first line of the input file. Each test case takes one line containing a circular sequence that is written as an arbitrary linear sequence. Since the circular sequences are DNA sequences, only four symbols, ‘A’, ‘C’, ‘G’ and ‘T’, are allowed. Each sequence has length at least 2 and at most 100.

Output

​   Print exactly one line for each test case. The line is to contain the lexicographically smallest sequence for the test case.

Sample Input

2
CGAGTCAGCT
CTCC

Sample Output

AGCTCGAGTC
CCCT

HINT

​   题目的大致意思是让你一个循环的字符串,从哪里看过去是最小的,用标准库函数来比较大小。这里采用将字符串复制一倍的办法来求出循环字符串中最小的一段。例如CTCC:

此时字符串的长度位原来的二倍,将从每一个向后4个长度的字符串用来和已知最小的字符串比较。

Accepted

#include<stdio.h>
#include<string.h> int main()
{
int sum;
scanf("%d", &sum);
while (sum--)
{
char arr[201];
scanf("%s", arr);
int len = strlen(arr);
strncpy(&arr[len], arr,len); //将字符串扩大复制一倍拼接在末尾
char min[101]; //用来保存最小的字符串
strncpy(min, arr, len); //对存储最小字符串的数组进行初始化
for (int i = 0;i < len;i++) //比较
{
if (strncmp(min, &arr[i], len) > 0)
strncpy(min, &arr[i], len); }
min[len] = '\0'; //在字符串的末尾补上'\0'
printf("%s\n", min);
}
}
min[len] = '\0'; //在字符串的末尾补上'\0'
printf("%s\n", min);
}
}

Circular Sequence UVA - 1584的更多相关文章

  1. UVa 1584 Circular Sequence --- 水题

    UVa 1584 题目大意:给定一个含有n个字母的环状字符串,可从任意位置开始按顺时针读取n个字母,输出其中字典序最小的结果 解题思路:先利用模运算实现一个判定给定一个环状的串以及两个首字母位置,比较 ...

  2. UVa 1584 Circular Sequence(环形串最小字典序)

    题意  给你一个环形串   输出它以某一位为起点顺时针得到串的最小字典序 直接模拟   每次后移一位比較字典序就可以  注意不能用strcpy(s+1,s)这样后移  strcpy复制地址不能有重叠部 ...

  3. UVA.1584 环状序列

    UVA.1584 环状序列 点我看题面 题意分析 给出你一段换装DNA序列,然后让你输出这段环状序列的字典序最小的序列情况. 字典序字面意思上理解就是按照字典编排的序列,其实也可以理解为按照ASCII ...

  4. uva 1584.Circular Sequence

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  5. Circular Sequence,ACM/ICPC Seoul 2004,UVa 1584

    #include <stdio.h> #include <string.h> #define maxn 105 int lss(const char *s,int p,int ...

  6. 字典序UVa 1584 Circular Sequence

    #include <iostream> #include <algorithm> #include <cmath> #include <cstdio> ...

  7. UVa -1584 Circular Sequence 解题报告 - C语言

    1.题目大意 输入长度为n$(2\le n\le 100)$的环状DNA串,找出该DNA串字典序最小的最小表示. 2.思路 这题特别简单,一一对比不同位置开始的字符串的字典序,更新result. 3. ...

  8. 【例题3-6 UVA - 1584】Circular Sequence

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 不用真的把每一位都取出来. 用一个后缀的思想. 把原串复制一遍接在后面,然后把每个字符串 都当成一个长度为n的后缀就好了. 比较每个 ...

  9. [置顶] ※数据结构※→☆线性表结构(queue)☆============循环队列 顺序存储结构(queue circular sequence)(十)

    循环队列 为充分利用向量空间,克服"假溢出"现象的方法是:将向量空间想象为一个首尾相接的圆环,并称这种向量为循环向量.存储在其中的队列称为循环队列(Circular Queue). ...

随机推荐

  1. c#(winform)获取本地打印机

    引用 using System.Drawing.Printing; //代码 PrintDocument prtdoc = new PrintDocument(); string strDefault ...

  2. 第一篇文章 vim的使用

    这么长时间以来,一直没有在博客园上写过博文.那第一篇博文就以vim的使用为开端吧. 不知道有多少人还在用着ctrl+c,ctrl+v这种方式,不过,就我个人而言,还是很倾向于vim的.不管是在服务器上 ...

  3. nacos--配置中心之客户端

    nacos提供com.alibaba.nacos.api.config.ConfigService作为客户端的API用于发布,订阅,获取配置信息: ConfigService获取配置信息流程: 优先使 ...

  4. 后端程序员之路 14、NumPy

    NumPy - NumPyhttp://www.numpy.org/ NumPy-快速处理数据 - 用Python做科学计算http://old.sebug.net/paper/books/scipy ...

  5. 虚拟机测试cobbler,网络安装加载最后出现 dracut:/#

    1.cobbler的几个重要概念: distro:发行版系统容,我理解为镜像来源,提供了kernel 和 initrd 文件以及repo源 profile:kickstart文件,用于定制系统,定制安 ...

  6. Linux速通04 用户、群组、权限

    用户及passwd文件 # /etc/passwd文件的功能:存储所有用户的相关信息,实际上是存放用户信息的数据库(database) # 各个字段的含义: * 第一个字段(列)记录的是这个用户的名字 ...

  7. Java 语言基础 02

    语言基础·二级 顺序结构语句 * A:什么是流程控制语句    * 流程控制语句:可以控制程序的执行流程. * B:流程控制语句的分类    * 顺序结构    * 选择结构    * 循环结构 *  ...

  8. Java小tips之命令行传参

    在命令行运行主函数时,后缀字符串,则会储存在args[]数组中,这种方法可以在程序运行时,借助Main函数传参 主类书写不规范见谅 ```java public class hello{ public ...

  9. AtCoder Beginner Contest 171-175 F

    171 F - Strivore 直接把初始字符当成隔板,统计的方案数会有重复 为了避免重复情况,规定隔板字母尽可能最后出现,即在隔板字母后面不能插入含隔板字母的字符串 所以在隔板字母后插入的字符只有 ...

  10. FreeBSD 12.2 已经发布 从现有版本更新到12

    #freebsd-update -r 12.2-RELEASE upgrade 如果提示更新第三方软件后,再执行freebsd-update install , 请输入 #pkg update &am ...