Stone-paper-scissors-lizard-Spock on Uri Online Judge ex. 1873, but he does not accept

0

My attempt:

#include <stdio.h>
#include <string.h>

int main() {
  char rajesh[15], sheldon[15];
  char pedra[] = "pedra", papel[] = "papel", tesoura[] = "tesoura",
  lagarto[] = "lagarto", spock[] = "spock";
  int c, i, comp;

  printf("Digite a quantidade de casos de teste: \n");
  scanf("%d", &c);
  for(i = 0; i < c; i++) {
    printf("Digite uma frase: \n");
    scanf(" %s %s", rajesh, sheldon);
    comp = strcmp(rajesh, sheldon);
    if(comp == 0) {
      printf("empate\n");
    }
    if(comp != 0) {
      if((strcmp(rajesh, tesoura) == 0) && ((strcmp(sheldon, papel) == 0) ||
        (strcmp(sheldon, lagarto) == 0))){
        printf("radesh\n");
      } else if((strcmp(sheldon, tesoura) == 0) && ((strcmp(rajesh, papel) == 0) ||
        (strcmp(sheldon, lagarto) == 0))){
        printf("sheldon\n");
      }

      if((strcmp(rajesh, papel) == 0) && ((strcmp(sheldon, pedra) == 0) ||
        (strcmp(sheldon, spock) == 0))){
        printf("radesh\n");
      } else if((strcmp(sheldon, papel) == 0) && ((strcmp(rajesh, pedra) == 0) ||
        (strcmp(rajesh, spock) == 0))){
        printf("sheldon\n");
      }

      if((strcmp(rajesh, pedra) == 0) && ((strcmp(sheldon, lagarto) == 0) ||
        (strcmp(sheldon, tesoura) == 0))){
        printf("radesh\n");
      } else if((strcmp(sheldon, pedra) == 0) && ((strcmp(rajesh, lagarto) == 0) ||
        (strcmp(rajesh, tesoura) == 0))){
        printf("sheldon\n");
      }

      if((strcmp(rajesh, lagarto) == 0) && ((strcmp(sheldon, spock) == 0) ||
        (strcmp(sheldon, papel) == 0))){
        printf("radesh\n");
      } else if((strcmp(sheldon, lagarto) == 0) && ((strcmp(rajesh, spock) == 0) ||
        (strcmp(rajesh, papel) == 0))){
        printf("sheldon\n");
      }

      if((strcmp(rajesh, spock) == 0) && ((strcmp(sheldon, tesoura) == 0) ||
        (strcmp(sheldon, pedra) == 0))){
        printf("radesh\n");
      } else if((strcmp(sheldon, spock) == 0) && ((strcmp(rajesh, tesoura) == 0) ||
        (strcmp(rajesh, pedra) == 0))){
        printf("sheldon\n");
      }
    }
  }

  return 0;
}

Link to the statement: link

    
asked by anonymous 27.06.2018 / 00:59

1 answer

1

Look at this:

    if(comp == 0) {
      printf("empate\n");
    }
    if(comp != 0) {

Now, if the first if is entered, the second automatically does not enter and vice versa. So it's better to use else here instead of another if .

Then, these% mounts of% s were meant to be if :

      if((strcmp(rajesh, tesoura) == 0) && ((strcmp(sheldon, papel) == 0) ||
        (strcmp(sheldon, lagarto) == 0))){
        printf("radesh\n");
      } else if((strcmp(sheldon, tesoura) == 0) && ((strcmp(rajesh, papel) == 0) ||
        (strcmp(sheldon, lagarto) == 0))){
        printf("sheldon\n");
      } else if((strcmp(rajesh, papel) == 0) && ((strcmp(sheldon, pedra) == 0) ||
        (strcmp(sheldon, spock) == 0))){
        printf("radesh\n");
      } else if((strcmp(sheldon, papel) == 0) && ((strcmp(rajesh, pedra) == 0) ||
        (strcmp(rajesh, spock) == 0))){
        printf("sheldon\n");
      }

The reason is that it should only fall into else if . The way you did, without forcing everything to be printf , several else if s are fired.

The code looks like this:

    if (comp == 0) {
        printf("empate\n");
    } else if ((strcmp(rajesh, tesoura) == 0) && ((strcmp(sheldon, papel) == 0) || (strcmp(sheldon, lagarto) == 0))) {
        printf("radesh\n");
    } else if ((strcmp(sheldon, tesoura) == 0) && ((strcmp(rajesh, papel) == 0) || (strcmp(sheldon, lagarto) == 0))) {
        printf("sheldon\n");
    } else if ((strcmp(rajesh, papel) == 0) && ((strcmp(sheldon, pedra) == 0) || (strcmp(sheldon, spock) == 0))) {
        printf("radesh\n");
    } else if ((strcmp(sheldon, papel) == 0) && ((strcmp(rajesh, pedra) == 0) || (strcmp(rajesh, spock) == 0))) {
        printf("sheldon\n");
    } else if ((strcmp(rajesh, pedra) == 0) && ((strcmp(sheldon, lagarto) == 0) || (strcmp(sheldon, tesoura) == 0))) {
        printf("radesh\n");
    } else if ((strcmp(sheldon, pedra) == 0) && ((strcmp(rajesh, lagarto) == 0) || (strcmp(rajesh, tesoura) == 0))) {
        printf("sheldon\n");
    } else if ((strcmp(rajesh, lagarto) == 0) && ((strcmp(sheldon, spock) == 0) || (strcmp(sheldon, papel) == 0))) {
        printf("radesh\n");
    } else if ((strcmp(sheldon, lagarto) == 0) && ((strcmp(rajesh, spock) == 0) || (strcmp(rajesh, papel) == 0))) {
        printf("sheldon\n");
    } else if ((strcmp(rajesh, spock) == 0) && ((strcmp(sheldon, tesoura) == 0) || (strcmp(sheldon, pedra) == 0))) {
        printf("radesh\n");
    } else if ((strcmp(sheldon, spock) == 0) && ((strcmp(rajesh, tesoura) == 0) || (strcmp(rajesh, pedra) == 0))) {
        printf("sheldon\n");
    }

Then look at these two lines:

  printf("Digite a quantidade de casos de teste: \n");
    printf("Digite uma frase: \n");

URI issues are extremely strict and inflexible in terms of input and output format, so even a blank space or less makes it say that your program is wrong. These two messages above will appear in the output and make the URI consider its solution invalid. Remove these messages.

Incidentally, the format of the URI also does not tolerate any typing or spelling errors in the output. The player name is ra j esh and not ra d esh .

And we have this:

    scanf(" %s %s", rajesh, sheldon);

Are you sure it was not to be printf instead of "%s %s" ? I think that blank space at the beginning can get in your way.

There are a lot more things I could suggest so that this% bundle% s will have a legal structure and not this horrible, repetitive thing. However, there I would have to practically rewrite your entire program.

    
27.06.2018 / 01:27