首页 > 其他 > 详细

UVA621 Secret Research【水题】

时间:2019-02-17 17:48:02      阅读:297      评论:0      收藏:0      [点我收藏+]

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;
}

UVA621 Secret Research【水题】

原文:https://www.cnblogs.com/tigerisland45/p/10391911.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!