Last active
September 26, 2016 02:27
-
-
Save rogerioagjr/ff24a6744ad05a789af9cca7c37d1fb8 to your computer and use it in GitHub Desktop.
Medalhas - F2PJ
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
// Medalhas - F2PJ - OBI 2016 | |
// Rogério Júnior | |
// Complexidade: O(1) | |
#include "iostream" | |
using namespace std; | |
int main(){ | |
int t1, t2, t3; | |
cin >> t1 >> t2 >> t3; | |
// vou descobrir quem é o primeiro colocado: | |
if(t1<t2 and t1<t3){ // se for o atleta 1, imprimo 1 | |
cout << "1\n"; | |
} | |
if(t2<t1 and t2<t3){ // se for o atleta 2, imprimo 2 | |
cout << "2\n"; | |
} | |
if(t3<t1 and t3<t2){ // se for o atleta 3, imprimo 3 | |
cout << "3\n"; | |
} | |
// agora, vou descobrir quem é o segundo colocado | |
// nessa pate, devemos ter muito cuidado em colocar os parêntesis | |
// pois temos vária condições dentro de um mesmo "if" | |
// os parêntesis devem separar corretamente as condições | |
// para que o coputador saiba dar a prioridade desejada ao "and" e ao "or" | |
if((t2>t1 and t1>t3) or (t3>t1 and t1>t2)){ // se for o atleta 1, imprimo 1 | |
cout << "1\n"; | |
} | |
if((t1>t2 and t2>t3) or (t3>t2 and t2>t1)){ // se for o atleta 2, imprimo 2 | |
cout << "2\n"; | |
} | |
if((t1>t3 and t3>t2) or (t2>t3 and t3>t1)){ // se for o atleta 3, imprimo 3 | |
cout << "3\n"; | |
} | |
// por fim, basta descobrir quem é o terceiro | |
if(t1>t2 and t1>t3){ // se for o atleta 1, imprimo 1 | |
cout << "1\n"; | |
} | |
if(t2>t1 and t2>t3){ // se for o atleta 2, imprimo 2 | |
cout << "2\n"; | |
} | |
if(t3>t1 and t3>t2){ // se for o atleta 3, imprimo 3 | |
cout << "3\n"; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment