We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Cats and a Mouse
Cats and a Mouse
+ 11 comments this problem should be of 10 points, not 15
+ 5 comments Python 3:
def catAndMouse(x, y, z): a = abs(x-z) b = abs(y-z) return "Cat A" if a<b else "Cat B" if b<a else "Mouse C"
+ 1 comment one line c++:
string catAndMouse(int x, int y, int z) { return (abs(x - z) < abs(y - z)) ? "Cat A" : (abs(x - z) > abs(y - z)) ? "Cat B" : "Mouse C"; }
how is this worth 15 points lol
+ 4 comments The default C++ code is nonsense.
for(int a0 = 0; a0 < q; a0++){ int x; int y; int z; cin >> x >> y >> z; vector <string> result = catAndMouse(x, y, z); for (ssize_t i = 0; i < result.size(); i++) { cout << result[i] << (i != result.size() - 1 ? " " : ""); } cout << endl; }
There's no point in expecting the user to return a sentence by filling a vector with single words in order to print them separated with spaces. I think it is counter-intuitive and needlessly confusing, and it should be refactored like so:
for (int a0 = 0; a0 < q; a0++) { int x, y, z; cin >> x >> y >> z; string result = catAndMouse(x, y, z); cout << result << endl; }
with the return type of catAndMouse changed to string.
+ 5 comments java 8:
static String catAndMouse(int x, int y, int z) { if(Math.abs(x - z) < Math.abs(y-z)){ return "Cat A"; } else if (Math.abs(x - z) > Math.abs(y-z)){ return "Cat B"; } else{ return "Mouse C"; } }
Load more conversations
Sort 902 Discussions, By:
Please Login in order to post a comment