Please use c++ Use cpp.sh compilier Two cats named A and B are standing at integ
ID: 3903497 • Letter: P
Question
Please use c++ Use cpp.sh compilier Two cats named A and B are standing at integral points on a line. Cat A is standing at point r and cat B is standing at point y. Both cats run at the same speed, and they want to catch a mouse named C that is hiding at integral point z on the line. You are given a number of test cases in the form of x, y, and z. For each test case, print the appropriate answer on a new line: If cat A catches the mouse first, print "Cat A". If cat B catches the mouse first, print "Cat B". If both cats reach the mouse at the same time, the two cats fight and the mouse escapes. In this case print "Mouse C". Input Format The first line contains a single integer T denoting the number of test cases. . Each of the subsequent T lines contains three space-separated integers describing the respective values of x (cat A's location), y (cat B's location), and z (mouse C's location) on the line. Constraints 1sx, y, zs 100 Output Format On a new line for each test case, print "Cat A" if cat A catches the mouse first, "Cat B" if cat B catches the mouse first, or "Mouse C" if the mouse escapes. Sample Input 1 23 132 213 Sample OutputExplanation / Answer
Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts. Thanks
//CODE
#include <iostream>
#include <math.h> //for abs() method
using namespace std;
int main()
{
int numTestCases;
//getting number of test cases (input line 1)
cin>>numTestCases;
//declaring x, y, z arrays for storing all test cases
int x[numTestCases],y[numTestCases],z[numTestCases];
//reading all test cases
for(int i=0;i<numTestCases;i++){
cin>>x[i];
cin>>y[i];
cin>>z[i];
}
//looping through each test case
for(int i=0;i<numTestCases;i++){
//finding the difference between Cat A and mouse
int catAdistance=abs(x[i]-z[i]);
//finding the difference between Cat B and mouse
int catBdistance=abs(y[i]-z[i]);
//printing stats based on the distances
if(catAdistance < catBdistance){
//cat A is more closer to the mouse
cout<<"Cat A"<<endl;
}else if(catAdistance > catBdistance){
//cat B is more closer to the mouse
cout<<"Cat B"<<endl;
}else{
//equal distance
cout<<"Mouse C"<<endl;
}
}
}
//Test cases 1
3
1 2 3
1 3 2
2 1 3
//OUTPUT 1
Cat B
Mouse C
Cat A
//Test cases 2
6
25 75 70
33 86 59
47 29 89
18 19 82
84 17 18
84 68 76
//OUTPUT 2
Cat B
Cat A
Cat A
Cat B
Cat B
Mouse C