Created
June 3, 2016 16:38
-
-
Save rogerioagjr/34e40ad0c889ceb65121c8bc9fa39935 to your computer and use it in GitHub Desktop.
Jogo de par ou ímpar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Jogo de par ou ímpar - F1PJ/F1P1 - OBI 2016 | |
// Rogério Júnior | |
// Complexidade: O(1) | |
#include <cstdio> // scanf e printf | |
int main(){ | |
// declaro as variáveis que vou usar | |
int p, d1, d2; | |
// leio os valores de p, d1 e d2 | |
scanf("%d %d %d", &p, &d1, &d2); | |
// se a soma de d1 e d2 for par | |
if((d1+d2)%2==0){ | |
// então ganhará quem pediu par | |
// se Alice pediu par | |
if(p==0){ | |
// então Alice ganha | |
printf("0\n"); | |
} | |
// caso Alice não tenha pedido par | |
else{ | |
// então Bob ganha | |
printf("1\n"); | |
} | |
} | |
// se a soma de d1 e d2 não for par | |
else{ | |
// então quem pediu ímpar ganha | |
// se Alice pediu par | |
if(p==0){ | |
// então Bob ganha | |
printf("1\n"); | |
} | |
// se Alice não pediu par | |
else{ | |
// então Alice ganha | |
printf("0\n"); | |
} | |
} | |
// ao fim do programa, retorno 0 | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment