zoukankan      html  css  js  c++  java
  • uva 1584 Circular Sequence (字符串处理)

    C - Circular Sequence
    Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu
    Submit Status

    Description

    Download as PDF
     

    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.

    epsfbox{p3225.eps}

    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, ACG 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

    问一个循环的字符串的最小字典序....
    好像没说清== 
    这题的关键在于想到用substr...
    感觉c++的string 比c 的字符数组高到不知哪里去了...
     1 /*************************************************************************
     2     > File Name: code/uva/1584.cpp
     3     > Author: 111qqz
     4     > Email: rkz2013@126.com 
     5     > Created Time: 2015年09月15日 星期二 17时04分52秒
     6  ************************************************************************/
     7 
     8 #include<iostream>
     9 #include<iomanip>
    10 #include<cstdio>
    11 #include<algorithm>
    12 #include<cmath>
    13 #include<cstring>
    14 #include<string>
    15 #include<map>
    16 #include<set>
    17 #include<queue>
    18 #include<vector>
    19 #include<stack>
    20 #include<cctype>
    21 #define y1 hust111qqz
    22 #define yn hez111qqz
    23 #define j1 cute111qqz
    24 #define ms(a,x) memset(a,x,sizeof(a))
    25 #define lr dying111qqz
    26 using namespace std;
    27 #define For(i, n) for (int i=0;i<int(n);++i)  
    28 typedef long long LL;
    29 typedef double DB;
    30 const int inf = 0x3f3f3f3f;
    31 const int N=1E2+7;
    32 string st;
    33 string ans;
    34 int len;
    35 int main()
    36 {
    37   #ifndef  ONLINE_JUDGE 
    38     freopen("in.txt","r",stdin); 
    39   #endif
    40     int T;
    41     cin>>T;
    42     while (T--)
    43     {
    44     cin>>st;
    45     len = st.length();
    46      ans = st;
    47     for (int i = 0 ; i < len ; i++)
    48     {
    49         string tmp =st.substr(i+1)+st.substr(0,i+1);
    50         if (tmp<ans) ans = tmp;
    51     }
    52     cout<<ans<<endl;
    53 
    54     
    55     }
    56   
    57   
    58  #ifndef ONLINE_JUDGE  
    59   fclose(stdin);
    60   #endif
    61     return 0;
    62 }
    View Code


  • 相关阅读:
    openAI的仿真环境Gym Retro的Python API接口(续1)—— 游戏过程记录及回放
    openAI的仿真环境Gym Retro的Python API接口
    如何使用Python环境下的2D经典游戏仿真器(openai推出的)retro库运行游戏"刺猬索尼克" (SonicTheHedgehog-Genesis)
    运行openai的gym代码报错提示import pyglet,安装后依然报错:ImportError: sys.meta_path is None, Python is likely shutting down
    “阿里事件”的结束真的是结束吗
    BMS(电池管理系统)第二课——一文说清各大IC厂商模拟前端(AFE)优缺点
    BMS(电池管理系统)第一课——BMS系统框架简介什么是BMS?
    Linux内核调试技术——kprobe使用与实现
    Qt事件:changeEvent(改变事件)
    ImGui-imgui实例解析之ShowDemoWindowWidgets-Basic
  • 原文地址:https://www.cnblogs.com/111qqz/p/4811277.html
Copyright © 2011-2022 走看看