October 29, 2018

E Maze In Program Logic in java

/**
 * Ankit is in maze. The command center sent him a string which decodes to come out from the maze. He is initially at (0, 0). String contains L, R, U, D denoting left, right, up and down. In each command he will traverse 1 unit distance in the respective direction.
 * For example if he is at (2, 0) and the command is L he will go to (1, 0).
 *
 * SAMPLE INPUT : LLRDDR
 * SAMPLE OUTPUT : 0 -2
 *
 */
package com.hackerearth.basicprograming;
import java.util.Scanner;
/**
 * @author consumerfed
 *
 */
public class EMazeIn {

/**
* @param args
*/
public static void main(String[] args) {
int x = 0;
int y = 0;
Scanner sc = new Scanner(System.in);
String traverse = sc.nextLine();
for(int i=0;i<traverse.length();i++) {
char movement = traverse.charAt(i);
switch (movement) {
case 'L':
x =x -1;
break;
case 'D':
y = y -1;
break;
case 'R':
x = x + 1;
break;
case 'U':
y = y + 1;
break;

default:
break;
}
}
System.out.println( x + " "+y );
}
}

SAMPLE INPUT : LLRDDR

SAMPLE OUTPUT : 0 -2

8 comments:

  1. But unlike other SEO companies London or elsewhere, we forge long term partnerships for
    long-lasting success. They would try to make your site famous through social networking sites like my space,
    Facebook, Twitter, Digo, Digg, Delicious, etc as a part of their SEO services
    London. Many organisations are finding that they have a better outcome when they employ a service to perform their London web design as well as Facebook development and social media UK options.

    ReplyDelete
  2. You will draw more loyal readers to your site and keep your readers coming back
    because you are sharing the best with them. Furthermore,
    a keyword should never feel like it is forced awkwardly to fit
    into content. Whether you promote yourself as a solo or business brand (< learn 10 ways to improve your SEO with Google+) Google+ is now a necessity.

    ReplyDelete
  3. AnonymousJune 02, 2019

    It is just the process of making specific search phrases, that are relevant to your website visible high up
    in the search engine rankings. They do their level best to make a site attractive and
    beautiful. Taking a look at other company's
    websites within a particular niche field can clue you in to what's being actively searched for,
    and what's not.

    ReplyDelete
  4. AnonymousJune 03, 2019

    Some SEO companies may only offer basic professional SEO services.
    There are always product demonstrations and distinctive displays unfold through Hamleys
    seven dynamic floors. You can get the contact details of the various seo companies by surfing around the globally web and create sure that you go through details of the training organization successfully before you be a part of your name for having a bright
    profession ahead.

    ReplyDelete
  5. AnonymousJune 04, 2019

    So, additional efforts have to be undertaken to develop the visiting page of your website.
    They do their level best to make a site attractive and beautiful.
    You can get the contact details of the various seo companies by surfing around
    the globally web and create sure that you go through details of the training organization successfully before you be a part of your
    name for having a bright profession ahead.

    ReplyDelete
  6. AnonymousJune 10, 2019

    But unlike other SEO companies London or elsewhere, we forge long term partnerships for
    long-lasting success. Each of the images on your web site should really have proper detailed titles and alt tags too.
    By using a service that can provide you will all of the various choices, you
    will save time and money getting online and noticed.

    ReplyDelete
  7. AnonymousJune 26, 2019

    But unlike other SEO companies London or elsewhere, we forge long term partnerships for
    long-lasting success. It provides flexible operating here we are at the employees and one can have pretty large wage along with
    the appropriate spare time. asia expert in providing website
    designing, website development, seo services, website hosting, digital
    marketing services and offering professional readymade scripts without any hesitation work and these Yourneeds.

    ReplyDelete
  8. AnonymousJuly 11, 2019

    You will draw more loyal readers to your site and keep your
    readers coming back because you are sharing the best with them.
    There are always product demonstrations and distinctive displays unfold through Hamleys seven dynamic floors.
    By using a service that can provide you will all of the various choices,
    you will save time and money getting online and noticed.

    ReplyDelete

Your feedback may help others !!!

Facebook comments