Saturday 20 April 2019

Power of Thor - Episode 1 CodinGame Solution in Java

Solution:-
import java.util.*;
import java.io.*;
import java.math.*;

class Player
{
    public static void main(String args[])
    {
        Scanner in = new Scanner(System.in);
        int lightX = in.nextInt(); // the X position of the light of power
        int lightY = in.nextInt(); // the Y position of the light of power
        int initialTX = in.nextInt(); // Thor's starting X position
        int initialTY = in.nextInt(); // Thor's starting Y position

        while (true)
        {
            int remainingTurns = in.nextInt(); // The level of Thor's remaining energy, representing the number of moves he can still make.
            String direction = "";
           
            if (initialTY < lightY)
            {
                initialTY++;
                direction = "S";
            }
           
            else if (initialTY > lightY)
            {
                initialTY--;
                direction = "N";
            }
           
            if (initialTX < lightX)
            {
                initialTX++;
                direction += "E";
            }
           
            else if (initialTX > lightX)
            {
                initialTX--;
                direction += "W";
            }
           
            System.out.println(direction);
        }
    }

}

No comments:

Post a Comment

Error While embed the video in Your website page

Error:- Refused to display '<URL>' in a frame because it set 'X-Frame-Options' to 'sameorigin Solution:- if ...