Help Lost Child Display: Harry, a little boy was accompanied by his Dad to visit the “Aquatica Carnival”. The event saw a large crowd and the Security Chiefs found it hard to control them. Very regretfully, Harry got lost and was seen extremely worried. He wanted to reach back home as soon as possible. He was standing currently at coordinates (x1, y1) in 2-D plane. His home is at coordinates (x2, y2).
Please help him by giving a command by telling the direction in which he should go, so as to reach his home. If you give him a direction, he will keep moving in that direction till he reaches home. There are four possible directions you can give as command – “left”, “right”, “up”, “down”. It might be possible that you can’t instruct Harry in such a way that he reaches his home. In that case, display the output as “sad”.
Input Format:
First line of the input contains four space separated integers x1, y1, x2, y2.
Output Format:
Output a single line containing “left” or “right” or “up” or “down” or “sad” (without quotes).
Refer sample input and output for formatting specifications.
Sample Input 1:
0 0 1 0
Sample Output 1:
right
Sample Input 2:
0 0 1 1
Sample Output 2:
sad
Solution
import java.util.*;
import java.lang.*;
import java.io.*;
class Main {
//sauravhathi
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
while(sc.hasNext()){
//sauravhathi
int a=sc.nextInt();
int b=sc.nextInt();
int c=sc.nextInt();
int d=sc.nextInt();
//sauravhathi
if(a!=c && b!=d) System.out.println("sad");
else if(a>c) System.out.println("left");
else if(a<c) System.out.println("right");
else if(b>d) System.out.println("down");
else if(b<d) System.out.println("up");
//sauravhathi
}
}}
Happy Learning – If you require any further information, feel free to contact me.