Circular Sequence UVA - 1584
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的更多相关文章
- UVa 1584 Circular Sequence --- 水题
UVa 1584 题目大意:给定一个含有n个字母的环状字符串,可从任意位置开始按顺时针读取n个字母,输出其中字典序最小的结果 解题思路:先利用模运算实现一个判定给定一个环状的串以及两个首字母位置,比较 ...
- UVa 1584 Circular Sequence(环形串最小字典序)
题意 给你一个环形串 输出它以某一位为起点顺时针得到串的最小字典序 直接模拟 每次后移一位比較字典序就可以 注意不能用strcpy(s+1,s)这样后移 strcpy复制地址不能有重叠部 ...
- UVA.1584 环状序列
UVA.1584 环状序列 点我看题面 题意分析 给出你一段换装DNA序列,然后让你输出这段环状序列的字典序最小的序列情况. 字典序字面意思上理解就是按照字典编排的序列,其实也可以理解为按照ASCII ...
- uva 1584.Circular Sequence
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- 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 ...
- 字典序UVa 1584 Circular Sequence
#include <iostream> #include <algorithm> #include <cmath> #include <cstdio> ...
- UVa -1584 Circular Sequence 解题报告 - C语言
1.题目大意 输入长度为n$(2\le n\le 100)$的环状DNA串,找出该DNA串字典序最小的最小表示. 2.思路 这题特别简单,一一对比不同位置开始的字符串的字典序,更新result. 3. ...
- 【例题3-6 UVA - 1584】Circular Sequence
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 不用真的把每一位都取出来. 用一个后缀的思想. 把原串复制一遍接在后面,然后把每个字符串 都当成一个长度为n的后缀就好了. 比较每个 ...
- [置顶] ※数据结构※→☆线性表结构(queue)☆============循环队列 顺序存储结构(queue circular sequence)(十)
循环队列 为充分利用向量空间,克服"假溢出"现象的方法是:将向量空间想象为一个首尾相接的圆环,并称这种向量为循环向量.存储在其中的队列称为循环队列(Circular Queue). ...
随机推荐
- 答不上的JUC笔试题
1:有一个总任务A,分解为子任务A1 A2 A3 ...,任何一个子任务失败后要快速取消所有任务,请写程序模拟. 「请寻求最优解,不要只是粗暴wait()」 本题解题思路:Fork/Join 通常使用 ...
- pandas的数据筛选之isin和str.contains函数
筛选是在平时的工作中使用非常频繁的功能,前文介绍了loc和iloc的筛选方法,现在继续介绍一些筛选的方法. DataFrame列表 以>,<,==,>=,<=来进行选择(& ...
- 使用gitlab构建基于docker的持续集成(二)
使用gitlab构建基于docker的持续集成(二) gitlab docker aspnetcore Centos配置gitlab镜像并且启动 Centos配置防火墙 windows上访问gitla ...
- React源码 commit阶段详解
转: React源码 commit阶段详解 点击进入React源码调试仓库. 当render阶段完成后,意味着在内存中构建的workInProgress树所有更新工作已经完成,这包括树中fiber节点 ...
- ASP.NET Core重复读取Request.Body
//HttpContext context.Request.EnableRewind(); //创建缓冲区存放Request.Body的内容,从而允许反复读取Request.Body的Stream u ...
- .Net Core 处理跨域问题Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource
网页请求报错: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Or ...
- 那些你不知道的DOU+投放技巧,以及常见的审核失败原因丨国仁网络
作为小额付费投放工具,DOU+一直深受各大中小商家的青睐.虽然它的审核比较严格,但转化效果还是非常明显的. 近日,抖音发布重要公告:内容低质的视频将无法购买DOU+推广,并可能因违反平台规则导致无法观 ...
- MySQL基本指令3 和 索引 、分页
1视图: -创建 create view 视图名称 as SQL ps:虚拟 -修改 alter view 视图名称 as SQL -删除 drop view 视图名称 2触发器 3自定义函 ...
- python的模块(module)和包(package)机制:import和from..import..
在python用import或者from...import来导入相应的模块. 模块其实就一些函数和类的集合文件,它能实现一些相应的功能,当我们需要使用这些功能的时候,直接把相应的模块导入到我们的程序中 ...
- JS逆向-抠代码的第二天【手把手学会抠代码】
今天的学习项目:沃支付:https://epay.10010.com/auth/login 清空浏览器缓存后,打开网页,输入手机号,密码222222,按照网站要求填入验证码(sorry,我没有账号密码 ...
