简体   繁体   English

有人请帮我找出这段代码的错误

[英]Someone please help me to find the mistakes of this code

What did I do wrong?我做错了什么?

I haven't used string library function in this code.我没有在这段代码中使用字符串库 function 。 I just used index position of the string to solve this code.我只是使用字符串的索引 position 来解决此代码。 But when I submit it in URI, it's showing wrong ans.但是当我在 URI 中提交它时,它显示错误的答案。 Can anyone help me, please!!谁能帮帮我,拜托!!

enter image description here在此处输入图像描述

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

    }
}

Why don't you use the index [2] of s and r :为什么不使用sr的索引[2]

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.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM