​   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. FTPClient类的API

    org.apache.commons.NET.ftp Class FTPClient类FTPClient java.lang.Object java.lang.Object继承 org.apache. ...

  2. Java基础语法:final修饰符

    一.final类 描述: 用'final'修饰的类不能被继承,没有子类. 例如,我们是无法写一个类去继承String类,然后对String类型扩展的,因为API中已经将String类定义为'final ...

  3. openwrt编译加载龙尚U9300模组上网

    硬件平台:MT7628A openwrt版本:MTK_SDK 1.添加模组信息 /build_dir/target-mipsel_24kc_musl/linux-ramips_mt76x8/linux ...

  4. spring 整合kafka监听消费

    前言 最近项目里有个需求,要消费kafka里的数据.之前也手动写过代码去消费kafka数据.但是转念一想.既然spring提供了消费kafka的方法.就没必要再去重复造轮子.于是尝试使用spring的 ...

  5. docker nacos 集群部署

    1.准备机器3台 192.168.101.14 192.168.101.15 192.168.101.16 2.初始化sql(如果我们要搭建集群的话,那么肯定是不能用内嵌的数据库,不然数据无法共享.集 ...

  6. 记录PHP post提交表单导入mysql中文乱码的问题

    记录记录PHP post提交表单导入mysql中文乱码的问题 关于乱码,这是个糟糕的问题!涉及到很多地方 解决思路:程序所涉及的环境字符集不一致导致 mysql出现乱码一般是mysql数据库内部的字符 ...

  7. Python 元类编程实现一个简单的 ORM

    概述 什么是ORM? ORM全称"Object Relational Mapping",即对象-关系映射,就是把关系数据库的一行映射为一个对象,也就是一个类对应一个表,这样,写代码 ...

  8. 通达OA后台getshell

    GIF演示图 https://github.com/jas502n/OA-tongda-RCE/blob/master/Auth-Getshell.gif 1.通过弱口令或其它手段进入后台 2.选择  ...

  9. mysql查询较长的执行进程及创建权限账号

    A:对于死锁,进程的操作 1.查找当前活跃事务 SELECT * from information_schema.INNODB_TRX 根据trx_started等判断事务是否异常锁定 2.杀死线程 ...

  10. HTTP 状态码(转载)

    本文由 简悦 SimpRead 转码, 原文地址 www.cnblogs.com HTTP 状态码 (HTTP Status Code) 状态码并不是每个都有,为了后期扩展.[update201705 ...