UVa 1584 Circular Sequence(环形串最小字典序)
题意 给你一个环形串 输出它以某一位为起点顺时针得到串的最小字典序
直接模拟 每次后移一位比較字典序就可以 注意不能用strcpy(s+1,s)这样后移 strcpy复制地址不能有重叠部分
#include<cstdio>
#include<cstring>
using namespace std;
const int N = 150;
char s[N], ans[N], c;
int t, l; int main()
{
scanf ("%d", &t);
while (t--)
{
scanf ("%s", s);
l = strlen (s);
strcpy (ans, s);
for (int i = 0; i < l; ++i)
{
c = s[l - 1];
for (int j = l - 1; j >= 1 ; --j)
s[j] = s[j - 1];
s[0] = c;
if (strcmp (s, ans) < 0)
strcpy (ans, s);
}
printf ("%s\n", ans);
}
}
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.
The following shows sample input and output for two test cases.
Sample
Input
2
CGAGTCAGCT
CTCC
Sample
Output
AGCTCGAGTC
CCCT
UVa 1584 Circular Sequence(环形串最小字典序)的更多相关文章
- UVa 1584 Circular Sequence --- 水题
UVa 1584 题目大意:给定一个含有n个字母的环状字符串,可从任意位置开始按顺时针读取n个字母,输出其中字典序最小的结果 解题思路:先利用模运算实现一个判定给定一个环状的串以及两个首字母位置,比较 ...
- uva 1584.Circular Sequence
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- 字典序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. ...
- 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 ...
- Circular Sequence UVA - 1584
Some DNA sequences exist in circular forms as in the following figure, which shows a circular sequ ...
- UVA.1584 环状序列
UVA.1584 环状序列 点我看题面 题意分析 给出你一段换装DNA序列,然后让你输出这段环状序列的字典序最小的序列情况. 字典序字面意思上理解就是按照字典编排的序列,其实也可以理解为按照ASCII ...
- 环状序列(Circular Sequence, ACM/ICPC Seoul 2004, UVa1584)
长度为n的环状串有n种表示法,分别为从某 个位置开始顺时针得到.例如,图3-4的环状串 有10种表示: CGAGTCAGCT,GAGTCAGCTC,AGTCAGCTCG等. 在这些表示法中,字典序最小 ...
- [ACM_模拟] ZJUT 1155 爱乐大街的门牌号 (规律 长为n的含k个逆序数的最小字典序)
Description ycc 喜欢古典音乐是一个 ZJUTACM 集训队中大家都知道的事情.为了更方便地聆听音乐,最近 ycc 特意把他的家搬到了爱乐大街(德语Philharmoniker-Stra ...
随机推荐
- java练习题-求int类型N值的阶乘
//求int类型N值的阶乘 public static int getNumsJieCheng(int i){ int rs = 1; if(i==0||i==1){ return i; } if(i ...
- [Android]有关外部链接唤醒App需要注意的坑
移动互联网发展到今天,一个移动app需要和各种各样的外部链接关联,它不再仅仅从手机的桌面启动,更多的将会从其他的应用.浏览器链接.短信.二维码或者微信分享等渠道启动,这里涉及到的是各种各样的营销渠道和 ...
- O-理解共享池
我们可以通过show sga命令查看共享池的整体组成部分: ....待截图.... 一.SGA内存结构 Oracle中SGA主要包括: 1.固定数据结构部分(FIXED Size) 2.数据块缓冲区( ...
- mysql_基础2
创建数据表:
- webstrom常用键
常用快捷键—Webstorm入门指南 提高代码编写效率,离不开快捷键的使用,Webstorm拥有丰富的代码快速编辑功能,你可以自由配置功能快捷键. 快捷键配置 点击“File”-> “setti ...
- CAD计算两曲线间最短路径(com接口)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...
- c# winform中使用WebKit实现网页与winform的交互
1.工作 一年多了,一直没对自己在工作遇到的问题进行总结,每次遇到问题都要在网上找资料,导致完成项目之后,时间久了就会生疏.所以下定 决定总结自己在工作中遇到的各种问题. 进入正题:第一次写还请大神多 ...
- join 和 left join 和 right join的区别?
join等价于 inner join 是内连接 ,返回两个表都有的符合条件的行. left join 是左连接,返回坐表中所有的行以及右表中符合条件的行. right join右连接,是返回右表中所有 ...
- 使用脚手架创建vue项目之后会有很多警告,如何关闭它!
依次打开build→webpack.base.conf.js文件,然后找到createLintingRule,把里面的内容选择性的删除即可,就是这么easy;
- 蓝桥-区间K大数查询
问题描述: 给定一个序列,每次询问序列中第l个数到第r个数中第K大的数是哪个. 输入格式 第一行包含一个数n,表示序列长度. 第二行包含n个正整数,表示给定的序列. 第三个包含一个正整数m,表示询问个 ...