设为首页 加入收藏

TOP

UVa/数组与字符串习题集(五)
2017-10-12 18:16:03 】 浏览:2528
Tags:UVa/ 字符串 习题集
scanf("%d", &n)==1 && n) { printf("Game %d:\n", ++kase); for(int i=0; i<n; ++i) scanf("%d", &a[i]); for(;;) { int A = 0, B = 0; for(int i=0; i<n; ++i) { scanf("%d", &b[i]); if(a[i] == b[i]) ++A; } if(!b[0]) break; for(int d=1; d<=9; ++d) { int c1 = 0, c2 = 0; for(int i=0; i<n; ++i) { if(a[i] == d) ++c1; if(b[i] == d) ++c2; } if(c1 < c2) B += c1; else B += c2; } printf(" (%d,%d)\n", A, B-A); } } return 0; }
UVa-1583.
Description:

For a positive integer N, the digit-sum of N is defined as the sum of N itself and its digits. When M
is the digitsum of N, we call N a generator of M.
For example, the digit-sum of 245 is 256 (= 245 + 2 + 4 + 5). Therefore, 245 is a generator of

  1. Not surprisingly, some numbers do not have any generators and some numbers have more than one
    generator. For example, the generators of 216 are 198 and 207.
    You are to write a program to find the smallest generator of the given integer.
Input:

Your program is to read from standard input. The input consists of T test cases. The number of test
cases T is given in the first line of the input. Each test case takes one line containing an integer N,
1 ≤ N ≤ 100,000.

Output:

Your program is to write to standard output. Print exactly one line for each test case. The line is to
contain a generator of N for each test case. If N has multiple generators, print the smallest. If N does
not have any generators, print ‘0’.

Sample Input:

3
216
121
2005

Sample Output:

198
0
1979

Codes:
//#define LOCAL

#include <cstdio>
#include <cstring>

#define maxn 100005
int ans[maxn];

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

    int T, n;
    memset(ans, 0, sizeof(ans));
    for(int m=1; m<maxn; ++m) {
        int x = m, y = m;
        while(x > 0) {
            y += x%10;
            x /= 10;
        }
        if(ans[y]==0 || m<ans[y]) ans[y] = m;
    }
    
    scanf("%d", &T);
    while(T--) {
        scanf("%d", &n);
        printf("%d\n", ans[n]);
    }

    return 0;
}
UVa-1584.
Description:

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 al-
ways read a circular sequence in the clockwise direction.
Since it is not easy to store a circular sequence in a com-
puter as it is, we decided to store it as a linear sequence.
However, there can be many linear sequences that are ob-
tained 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 e

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

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目