设为首页 加入收藏

TOP

UVa/数组与字符串习题集(三)
2017-10-12 18:16:03 】 浏览:2532
Tags:UVa/ 字符串 习题集
ach test case. The line is to contain the lexicographically smallest sequence
for the test case.

Sample Input:

2
CGAGTCAGCT
CTCC

Sample Output:

AGCTCGAGTC
CCCT

Codes:
//#define LOCAL

#include <cstdio>
#include <cstring>

#define maxn 105
char s[maxn];

int less(const char* s, int p, int q) {
    int n = strlen(s);
    for(int i=0; i<n; ++i) 
        if(s[(p+i)%n] != s[(q+i)%n])
            return s[(p+i)%n] < s[(q+i)%n];
    return 0;
}

int main()
{
    #ifdef LOCAL
        freopen("E:\\Temp\\input.txt", "r", stdin);
        freopen("E:\\Temp\\output.txt", "w", stdout);
    #endif

    int T;
    scanf("%d", &T);

    while(T--) {
        scanf("%s", s);
        int ans = 0;
        int n = strlen(s);
        for(int i=1; i<n; ++i)
            if(less(s, i, ans)) ans = i;
        for(int i=0; i<n; ++i)
            putchar(s[(i+ans)%n]);
        putchar('\n');
    }

    return 0;
}
首页 上一页 1 2 3 4 5 下一页 尾页 3/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇SID1190471 / 烦人的幻灯片 暴力.. 下一篇病毒

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目