What did I do wrong?
I haven't used string library function in this code. I just used index position of the string to solve this code. But when I submit it in URI, it's showing wrong ans. Can anyone help me, please!!
#include <stdio.h>
int main()
{
int c, i, x;
char s[10], r[10];
scanf("%d", &x);
for(i = 0, c = 0; i < x; i ){
scanf("%s%s", s, r);
c ;
if(s[4] == 'a' && r[0] == 'l' || s[4] == 'a' && r[0] == 't'){
printf("Caso #%d: Bazinga!\n", c);
}
else if(s[0] == 'l' && r[4] == 'a' || s[0] == 't' && r[4] == 'a'){
printf("Caso #%d: Raj trapaceou!\n", c);
}
else if(s[0] == 'p' && r[4] == 'a' || s[0] == 'p' && r[0] == 's'){
printf("Caso #%d: Bazinga!\n", c);
}
else if(s[4] == 'a' && r[0] == 'p' || s[0] == 's' && r[0] == 'p'){
printf("Caso #%d: Raj trapaceou!\n", c);
}
else if(s[0] == 't' && r[0] == 'p' || s[0] == 't' && r[0] == 'l'){
printf("Caso #%d: Bazinga!\n", c);
}
else if(s[0] == 'p' && r[0] == 't' || s[0] == 'l' && r[0] == 't'){
printf("Caso #%d: Raj trapaceou!\n", c);
}
else if(s[0] == 'l' && r[0] == 's' || s[0] == 'l' && r[0] == 'p'){
printf("Caso #%d: Bazinga!\n", c);
}
else if(s[0] == 's' && r[0] == 'l' || s[0] == 'p' && r[0] == 'l'){
printf("Caso #%d: Raj trapaceou!\n", c);
}
else if(s[0] == 's' && r[0] == 't' || s[0] == 's' && r[4] == 'a'){
printf("Caso #%d: Bazinga!\n", c);
}
else if(s[0] == 't' && r[0] == 's' || s[4] == 'a' && r[0] == 's'){
printf("Caso #%d: Raj trapaceou!\n", c);
}
else if(s[4] == 'a' && r[4] == 'a' || s[0] == 'p' && r[0] == 'p' || s[0] == 't' && r[0] == 't' || s[0] == 'l' && r[0] == 'l' || s[0] == 's' && r[0] == 's'){
printf("Caso #%d: De novo!\n", c);
}
}
}
CodePudding user response:
Why don't you use the index [2]
of s
and r
:
d: pedra
p: papel
s: tesoura
g: legarto
o: spock
Then the response would be
novo:
s[2] == r[2]
bazinga:
s[2] == 's' && r[2] == 'p'
s[2] == 'p' && r[2] == 'd'
s[2] == 'd' && r[2] == 'g'
s[2] == 'g' && r[2] == 'o'
s[2] == 'o' && r[2] == 's'
s[2] == 's' && r[2] == 'g'
s[2] == 'g' && r[2] == 'p'
s[2] == 'p' && r[2] == 'o'
s[2] == 'o' && r[2] == 'd'
s[2] == 'd' && r[2] == 's'
trapaceou: otherwise.