Cats and a Mouse

Two cats named  and  are standing at integral points on the x-axis. Cat  is standing at point  and cat  is standing at point . Both cats run at the same speed, and they want to catch a mouse named  that's hiding at integral point  on the x-axis. Can you determine who will catch the mouse?
You are given  queries in the form of , and . For each query, print the appropriate answer on a new line:
• If cat  catches the mouse first, print Cat A.
• If cat  catches the mouse first, print Cat B.
• If both cats reach the mouse at the same time, print Mouse C as the two cats fight and mouse escapes.
Input Format
The first line contains a single integer, , denoting the number of queries.
Each of the  subsequent lines contains three space-separated integers describing the respective values of  (cat 's location),  (cat 's location), and  (mouse 's location).
Constraints
Output Format
On a new line for each query, print Cat A if cat  catches the mouse first, Cat B if cat  catches the mouse first, or Mouse C if the mouse escapes.
Sample Input 0
3
1 2 3
1 3 2
2 1 3

Sample Output 0
Cat B
Mouse C
Cat A

Explanation 0
Query 0: The positions of the cats and mouse are shown below:
Cat  will catch the mouse first, so we print Cat B on a new line.
Query 1: In this query, cats  and  reach mouse  at the exact same time:
Because the mouse escapes, we print Mouse C on a new line.
Solution
using namespace std;
int main()
{
int q;
cin >> q;
for(int a0 = 0; a0 < q; a0++){
int x;
int y;
int z;
cin >> x >> y >> z;
if(abs(x-z)>abs(y-z))
cout<<"Cat B"<<endl;
else if(abs(x-z)<abs(y-z))
cout<<"Cat A"<<endl;
else
cout<<"Mouse C"<<endl;
}
return 0;
}

Share:

How to Make Environment Variable in Windows 10

What is an Environment Variable??

Environment variables are a set of dynamic named values that can affect the way running  processes will behave on a computer. They are part of the environment in which a  process runs.

Ever wanted to access any program just by typing it's name on command prompt?? Then  this is the guide for you.
In this guide I'll describe the complete process of setting environment variable, so that you  can use any program directly from control panel by just typing the name of .exe file.

Steps:-

1. In the ask Cortana tab type Control Panel and select Control Panel to directly access control  panel or you can just press the Start Button and then select Settings which is just above Power button.
2. Now select System, and scroll down to find About in the left pane. Select the About tab and then scroll down to find Related Settings under it select the System Info.
3. In the System Info screen you will see Advanced System Settings on the Left Side. Select Advanced System Settings. Now select the Environment Variables in the lower right.
4. Now in the System Variables window, Select Path and click Edit. Now select New and Click Browse or manually enter the path where the .exe file you want to use is located.

5. Click Ok and Save the settings.
6. Go to control panel and type the name of program you want to start(after adding it's path) you should now be able to access it directly.
It works great if you're a programmer and you need to compile as well as access editors like notepad++ and use g++ etc.

For more details kindly add a comment and I'll improve the post.
Share:

Circular Array Rotation

John Watson performs an operation called a right circular rotation on an array of integers, . After performing one right circular rotation operation, the array is transformed from  to .
Watson performs this operation  times. To test Sherlock's ability to identify the current element at a particular position in the rotated array, Watson asks  queries, where each query consists of a single integer, , for which you must print the element at index  in the rotated array (i.e., the value of ).
Input Format
The first line contains  space-separated integers, , and , respectively.
The second line contains  space-separated integers, where each integer  describes array element  (where ).
Each of the  subsequent lines contains a single integer denoting .
Constraints
Output Format
For each query, print the value of the element at index  of the rotated array on a new line.
Sample Input
3 2 3
1 2 3
0
1
2

Sample Output
2
3
1

Explanation
After the first rotation, the array becomes
After the second (and final) rotation, the array becomes .
Let's refer to the array's final state as array . For each query, we just have to print the value of  on a new line:
1. , so we print  on a new line.
2. , so we print  on a new line.
3. , so we print  on a new line.
Solution:-

#include <iostream>
using namespace std;
int main()
{
int n,k,q,m,j;
cin>>n>>k>>q;
k%=n;
int *A= new int[n] ;
for(int i=0;i<n;i++)
cin>>A[i];
for(int i=0;i<q;i++)
{
cin>>m;

j=m-k;
if(j<0)
cout<<A[n+j]<<endl;
else
cout<<A[j]<<endl;
}
return 0;
}
Share: