其他分享
首页 > 其他分享> > UVA621 Secret Research【水题】

UVA621 Secret Research【水题】

作者:互联网

At a certain laboratory results of secret research are thoroughly encrypted. A result of a single experiment is stored as an information of its completion:
    ‘positive result’, ‘negative result’, ‘experiment failed’ or ‘experiment not completed’
    The encrypted result constitutes a string of digits S, which may take one of the following forms:
    • positive result S = 1 or S = 4 or S = 78
    • negative result S = S35
    • experiment failed S = 9S4
    • experiment not completed S = 190S
    (A sample result S35 means that if we add digits 35 from the right hand side to a digit sequence then we shall get the digit sequence corresponding to a failed experiment)
    You are to write a program which decrypts given sequences of digits.
Input
A integer n stating the number of encrypted results and then consecutive n lines, each containing a sequence of digits given as ASCII strings.
Output
For each analysed sequence of digits the following lines should be sent to output (in separate lines):
    + for a positive result
    - for a negative result
    * for a failed experiment
    ? for a not completed experiment
    In case the analysed string does not determine the experiment result, a first match from the above list should be outputted.
Sample Input
4
78
7835
19078
944
Sample Output

问题链接UVA621 Secret Research
问题简述:(略)
问题分析
    给定一个字符串,若为“1”,“4”,“78”则输出‘+’;若最后两个字符为“35”则输出‘-’;若首字符为‘9’并且尾字符为‘4’则输出‘*‘;否则输出’?‘。
    简单的字符串判定题,用C语言的字符串库函数(string.h)就可以实现。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA621 Secret Research */

#include <bits/stdc++.h>

using namespace std;

const int N = 512;
char s[N];

int main()
{
    int n, len;
    scanf("%d", &n);
    while(n--) {
        scanf("%s", s);

        len = strlen(s);
        if(strcmp(s, "1") == 0 || strcmp(s, "4") == 0 || strcmp(s, "78") == 0)
            putchar('+');
        else if(s[len - 2] == '3' && s[len - 1] == '5')
            putchar('-');
        else if(s[0] == '9' && s[len - 1] == '4')
            putchar('*');
        else
            putchar('?');
        putchar('\n');
    }

    return 0;
}

标签:digits,putchar,水题,len,failed,Secret,experiment,result,UVA621
来源: https://www.cnblogs.com/tigerisland45/p/10391911.html