uva621
来源:互联网 发布:淘宝买家申请售后换货 编辑:程序博客网 时间:2024/06/15 20:36
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=562
621 - Secret Research
Time limit: 3.000 seconds
Secret ResearchAt a certain laboratory results of secret research arethoroughly encrypted. A result of a single experiment is stored asan information of its completion:
`positive result', `negative result', `experiment failed' or`experiment not completed'
The encrypted result constitutes a string of digits S, which maytake 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 theright hand side to a digit sequence then we shall get the digitsequence corresponding to a failed experiment)
You are to write a program which decrypts given sequences ofdigits.
Input
A integer n stating the number of encrypted results andthen consecutive n lines, each containing a sequence ofdigits given as ASCII strings.
Output
For each analysed sequence of digits the following lines shouldbe 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 experimentresult, a first match from the above list should be outputted.
SampleInput
478783519078944
SampleOutput
+-?*
题意:就按照题目中的要求顺序判断,符合之后不再判断后面的条件。贡献了好几次WA啊。。其中有一种方法挺好的就是把所有的情况都保存在数组里面,输入的时候直接比较,不过WA了。。
WA的代码1:
#include<stdio.h>
#include<string.h>
int s1[4]={1,4,78};
int s2[4]={135,435,7835};
int s3[4]={914,944,9784};
int s4[4]={1901,1904,19078};
int main()
{
}
WA的代码2
#include<stdio.h>
#include<string.h>
char s1[5][10]={"1","4","78"};
char s2[5][10]={"135","435","7835"};
char s3[5][10]={"914","944","9784"};
char s4[5][10]={"1901","1904","19078"};
int main()
{
}
AC代码:
#include<stdio.h>
#include<string.h>
char s[1010];
int main()
{
int n;
scanf("%d",&n);
getchar();
while(n--)
{
scanf("%s",s);
int len=strlen(s);
if(!strcmp(s,"1")||!strcmp(s,"4")||!strcmp(s,"78"))
{
printf("+\n");
continue;
}
else if(s[len-2]=='3'&&s[len-1]=='5')
{
printf("-\n");
continue;
}
else if(s[0]=='9'&&s[len-1]=='4')
{
printf("*\n");
continue;
}
else if((s[0]=='1')&&(s[1]=='9')&&(s[2]=='0'))
{
printf("?\n");
continue;
}
}
return 0;
}