博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【UVA】 1584 --- Circular Sequence
阅读量:2039 次
发布时间:2019-04-28

本文共 2215 字,大约阅读时间需要 7 分钟。

【UVA】 1584 --- Circular Sequence

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

#include 
#include
#include
bool find_min(int m, int n);using namespace std;char arr[101];int main(){
int x; cin >> x; while (x--) {
int min = 0; cin >> arr; int num = strlen(arr); for (int i = 0; i < num; i++) {
if (find_min(i, min)) {
min = i; } } for (int i = 0; i < num; i++) {
cout << arr[(min + i) % num]; } cout << endl; } return 0;}bool find_min(int m, int n){
int x = strlen(arr); for (int i = 0; i < x; i++) {
if (arr[(m + i) % x] != arr[(n + i) % x]) {
return arr[(m + i) % x] < arr[(n + i) % x]; } } return false;}

转载地址:http://qgyof.baihongyu.com/

你可能感兴趣的文章
excel poi 设置列宽度
查看>>
jquery ajax缓存问题解决方法小结
查看>>
spring 默认事务传播属性
查看>>
mysql 嵌套查询
查看>>
svn Cleanup failed to process the following paths错误的解决
查看>>
全国各个城市代码
查看>>
Netty 源码分析之 三 我就是大名鼎鼎的 EventLoop(一)
查看>>
Linux下MySQL备份以及crontab定时备份(crontab表达式简介)
查看>>
一个shiro授权的执行顺序
查看>>
js字符串截取函数slice()、substring()、substr()
查看>>
redis动态扩展内存
查看>>
linux root给其他用户赋予某个文件夹权限
查看>>
Redis 集群搭建
查看>>
Linux下查看某个端口下运行的程序
查看>>
细说Redis监控和告警
查看>>
服务器的上行和下行带宽
查看>>
计算一个接口的返回值大小(占用内存)
查看>>
jedis : NoSuchMethodError: org.springframework.util.Assert.isTrue(ZLjava/util/function/Supplier
查看>>
常见JedisConnectionException异常分析
查看>>
linux下常见命令
查看>>