UVA – 10082 – WERTYU

  • ID : UVA – 10082 – WERTYU
  • Submissions : Java – Accepted
  • Difficulty : Easy
  • Type : Simple Math, Logarithms
  • Time for Submission : 20 minutes
  • Solution Description :
    • preset the keyboard layout in a string and for every character seek it’s index and return the character at i-1.
  • Problems :
    • put two spaces at the beginning  and start searching at i =1 to avoid the space special case.
  • Code :

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String keyboard = "  `1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./";
		while (in.hasNext()) {
			String s = in.nextLine();
			for (char a : s.toCharArray())
				for (int b = 1; b < keyboard.length(); b++)
					if (a == keyboard.charAt(b))
                                                    System.out.print(keyboard.charAt(b - 1));
			System.out.println("");
		}
	}
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: