Last active
December 14, 2015 07:19
-
-
Save jdiez17/5050125 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#include <iostream> | |
#include <string> | |
#include <cstdlib> | |
#include <cmath> | |
using namespace std; | |
float evaluate(string frac) { | |
int num = -1, denum = -1; | |
string buf; | |
for(size_t i = 0; i < frac.length(); i++) { | |
if(frac[i] == '/') { | |
num = atoi(buf.c_str()); | |
buf = ""; | |
} else { | |
buf += frac[i]; | |
} | |
} | |
denum = atoi(buf.c_str()); | |
return (float)num / denum; | |
} | |
bool check(float n) { | |
return floor(n) == (int)n && n >= 1; | |
} | |
int main() { | |
int cases; | |
cin >> cases; | |
for(int i = 0; i < cases; i++) { | |
string frac1, frac2, frac3; | |
cin >> frac1 >> frac2 >> frac3; | |
float f1 = evaluate(frac1), f2 = evaluate(frac2), f3 = evaluate(frac3); | |
float sum = f1 + f2 + f3; | |
float coefficent = sum - 1; | |
float x = -2 / coefficent; | |
// Comprobar que no hay que partir ningún animal | |
bool valid = true; | |
valid &= check(f1 * x); | |
valid &= check(f2 * x); | |
valid &= check(f3 * x); | |
if(valid) | |
cout << x-1 << endl; | |
else | |
cout << "no" << endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment