Skip to content

Instantly share code, notes, and snippets.

@tinkerstudent
Created October 25, 2015 19:54
Show Gist options
  • Select an option

  • Save tinkerstudent/4c7ea6c9eaef5ee59d60 to your computer and use it in GitHub Desktop.

Select an option

Save tinkerstudent/4c7ea6c9eaef5ee59d60 to your computer and use it in GitHub Desktop.
package com.tinkeracademy.ap;
import java.util.Scanner;
public class Main {
/**
* Array of all possible alphabet inputs
*/
public static char[] alphabets = new char[] { 'a', 'b', 'c', 'd',
'e', 'f', 'g', 'h',
'i', 'j', 'k', 'l',
'm', 'n', 'o', 'p',
'q', 'r', 's', 't',
'u', 'v', 'w', 'x',
'y', 'z',
'A', 'B', 'C', 'D',
'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L',
'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X',
'Y', 'Z',
'0', '1', '2', '3',
'4', '5', '6', '7',
'8', '9',
',', '.', '?', '!',
'"', '\'', '`',
'(', ')', '[', ']',
'{', '}', '<', '>',
'&', '_', ' ',
'\u0250', 'q', '\u0254', 'p',
'\u01DD', '\u025F', '\u0183', '\u0265',
'\u1D09', '\u027E', '\u029E', '1',
'\u026F', 'u', 'o', 'd',
'b', '\u0279', 's', '\u0287',
'n', '\u028C', '\u028D', 'x',
'\u028E', 'z',
'\u2200', 'B', '\u0186', 'D',
'\u018E', '\u2132', '\u05E4', 'H',
'I', '\u017F', 'K', '\u02E5',
'W', 'N', 'O', '\u0500',
'Q', 'R', 'S', '\u2534',
'\u2229', '\u039B', 'M', 'X',
'\u2144', 'Z',
'0', '\u0196', '\u1105', '\u0190',
'\u3123', '\u03DB', '9', '\u3125',
'8', '6',
'\'', '\u02D9', '\u00BF', '\u00A1',
'\u201E', ',', ',',
')', '(', ']', '[',
'}', '{', '>', '<',
'\u214B', '\u203E', ' '
};
public static char[] reverseAlphabets = new char[] {
'\u0250', 'q', '\u0254', 'p',
'\u01DD', '\u025F', '\u0183', '\u0265',
'\u1D09', '\u027E', '\u029E', '1',
'\u026F', 'u', 'o', 'd',
'b', '\u0279', 's', '\u0287',
'n', '\u028C', '\u028D', 'x',
'\u028E', 'z',
'\u2200', 'B', '\u0186', 'D',
'\u018E', '\u2132', '\u05E4', 'H',
'I', '\u017F', 'K', '\u02E5',
'W', 'N', 'O', '\u0500',
'Q', 'R', 'S', '\u2534',
'\u2229', '\u039B', 'M', 'X',
'\u2144', 'Z',
'0', '\u0196', '\u1105', '\u0190',
'\u3123', '\u03DB', '9', '\u3125',
'8', '6',
'\'', '\u02D9', '\u00BF', '\u00A1',
'\u201E', ',', ',',
')', '(', ']', '[',
'}', '{', '>', '<',
'\u214B', '\u203E', ' ',
'a', 'b', 'c', 'd',
'e', 'f', 'g', 'h',
'i', 'j', 'k', 'l',
'm', 'n', 'o', 'p',
'q', 'r', 's', 't',
'u', 'v', 'w', 'x',
'y', 'z',
'A', 'B', 'C', 'D',
'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L',
'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X',
'Y', 'Z',
'0', '1', '2', '3',
'4', '5', '6', '7',
'8', '9',
',', '.', '?', '!',
'"', '\'', '`',
'(', ')', '[', ']',
'{', '}', '<', '>',
'&', '_', ' '
};
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
String input = s.nextLine();
String output = "";
for (int i = input.length() - 1; i >= 0; i--) {
char in = input.charAt(i);
int index = Main.findCharInAlphabetsArray(in);
char out = reverseAlphabets[index];
output = output + out;
}
System.out.println(output);
s.close();
}
public static int findCharInAlphabetsArray(char in) {
for (int i = 0; i < alphabets.length; i++) {
if (alphabets[i] == in) {
return i;
}
}
System.out.println("cannot find char for " + in);
return -1;
}
public static int findCharInReverseAlphabetsArray(char in) {
for (int i = 0; i < reverseAlphabets.length; i++) {
if (reverseAlphabets[i] == in) {
return i;
}
}
System.out.println("cannot find char for " + in);
return -1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment