UVa -1584 Circular Sequence 解题报告

1.题目大意

输入长度为n$(2\le n\le 100)$的环状DNA串,找出该DNA串字典序最小的最小表示。

2.思路

这题特别简单,一一对比不同位置开始的字符串的字典序,更新result。

3.代码

#include"stdio.h"
#include"string.h"
#define maxn 100

int judge(char* s,int p,int q) //比较p的字典序是否比q小
{
    int m=strlen(s);
    for(int i=0; i<m; i++)
        if(s[(p+i)%m]!=s[(q+i)%m])
            return s[(p+i)%m]<s[(q+i)%m];
    return 0;
}

int main()
{
    int T,i,m,result;
    char s[maxn];
    scanf("%d",&T);
    while(T--)
    {
        scanf("%s",s);
        m=strlen(s);
        for(i=0; i<m; i++)
            if(judge(s,i,result)) result=i;//如果i的字典序比result小,那么将i存入result中
        for(i=0; i<m; i++)
            printf("%c",s[(result+i)%m]);
        printf("\n");
    }
    return 0;
}

  

时间: 2024-10-24 07:57:21

UVa -1584 Circular Sequence 解题报告的相关文章

UVa 1584 Circular Sequence --- 水题

UVa 1584 题目大意:给定一个含有n个字母的环状字符串,可从任意位置开始按顺时针读取n个字母,输出其中字典序最小的结果 解题思路:先利用模运算实现一个判定给定一个环状的串以及两个首字母位置,比较二者字典序大小的函数, 然后再用一层循环,进行n次比较,保存最小的字典序的串的首字母位置,再利用模运算输出即可 /* UVa 1584 Circular Sequence --- 水题 */ #include <cstdio> #include <cstring> //字符串s为环状,

UVA 1584 - Circular Sequence(环状序列)(字典序)

1584 - Circular Sequence Time limit: 3.000 seconds 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 firs

uva 1584 Circular Sequence (字符串处理)

C - Circular Sequence Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Description Some DNA sequences exist in circular forms as in the following figure, which shows a circular sequence ``CGAGTCAGCT", that is,

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

UVa 1584 - Circular Sequence

哈哈哈哈,  又用Java强大的字符串API和集合类水过一道题,不服用C++来一遍看看比这个代码长多少(不考虑时间的情况下). import java.util.*; public class Main1584 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); ArrayList<String> arrlist = new ArrayList<String>(); St

hdu 1711 Number Sequence 解题报告

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1711 题目意思:给出一条有n个数的序列a[1],a[2],......,a[n],和一条有m 个数的序列b[1],b[2],......,b[m],求出b[1],b[2],...,b[m]在序列a中完全匹配时,在序列a中的位置,如果找不到输出-1. 这几天一直在学kmp,该题算是kmp的入门题吧.有个地方要稍稍注意,代码中,主串和模式串的比较初始值为-1,-1,否则如果从0开始,会默认第一个字符是相

USACO Section2.1 Sorting a Three-Valued Sequence 解题报告

sort3解题报告 —— icedream61 博客园(转载请注明出处)------------------------------------------------------------------------------------------------------------------------------------------------[题目] 给你N,而后给出N个数,每个数都是1~3中的一个.请问,要把这个数列升序排好,最少需要进行几次两两交换?[数据范围] 1<=N<

UVa 1548 Circular Sequence (字符串处理)

Circular Sequence Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description Some DNA sequences exist in circular forms as in the following figure, which shows a circular sequence ``CGAGTCAGCT", that is, t

Ducci Sequence解题报告

A Ducci sequence is a sequence of n-tuples of integers. Given an n-tuple of integers (a1, a2, ... , an), the next n-tuple in the sequence is formed by taking the absolute differences of neighboring integers: ( a1, a2, ... , an)  (| a1 - a2|,| a2 - a3