说说:这道题非常之坑!开始还以为要递归判断的,其实根本不用,只要判断第一层的S即可,其中内嵌的S肯定是正确的。居然还有这样的题目,真的很无语╮(╯_╰)╭
题目:
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:
加密的结果组成了一个数字串S,它将采用以下的某种形式
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)
(如结果S35意思是如果我们把数字35加到一个数字串的右边那么这就是个消极结果(译:原文为实验失败,我认为有误))
You are to write a program which decrypts given sequences of digits.
你需要写一个程序对数字串进行解密
整数n代表加密结果的数目,接下来的连续的n行,每行都是用ASCII码表示的数字串
分析完数字串后需要输出结果,且一行一个结果
+ 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.
万一数字串并为决定实验结果,输出上表中第一个匹配的项。
4 78 7835 19078 944
+ - ? *
源代码:
#include <stdio.h>
#include <string.h>
int main(){
int N,len;
char S[1000];
//freopen("data.txt","r",stdin);
scanf("%d",&N);
while(N--){
scanf("%s",S);
len=strlen(S);
if(len<=2){//是否为positive
printf("+\n");
continue;
}
if(S[0]=='9'&&S[len-1]=='4'){//是否为failed
printf("*\n");
continue;
}
if(S[len-1]=='5'){//是否为negative
printf("-\n");
continue;
}
printf("?\n");
}
return 0;
}Secret Research UVA 621,布布扣,bubuko.com
原文地址:http://blog.csdn.net/u011915301/article/details/38406469