Created
June 28, 2011 16:26
-
-
Save wingyplus/1051525 to your computer and use it in GitHub Desktop.
Problem A. License plate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class plate { | |
public static void main (String[] args) { | |
String input = System.console().readLine(); | |
String word = ""; | |
for (int i = 0; i < input.length(); i++) { | |
if (input.charAt(i) == ' ') { | |
check (word); | |
word = ""; | |
} else if (i == input.length() - 1) { | |
word += input.charAt(i); | |
check (word); | |
} else { | |
word += input.charAt(i); | |
} | |
} | |
} | |
private static void check (String input) { | |
int s_to_n = Integer.parseInt(input); | |
if (s_to_n > 0 && s_to_n < 10) { | |
System.out.println(input); | |
} else if (palindrome (input)) { | |
System.out.println(input); | |
} else if (s_to_n >= 100 && s_to_n % 100 == 0) { | |
System.out.println(input); | |
} else if (s_to_n > 1000 && input.substring(0, 1).equals(input.substring(2, 3))) { | |
System.out.println(input); | |
} else if (s_to_n > 100 && (checkLtoH(input) || checkHtoL(input))) { | |
System.out.println(input); | |
} | |
} | |
private static boolean palindrome (String input) { | |
for (int i = 0; i < input.length()/2; i++) { | |
if (input.charAt(i) != input.charAt(input.length() - i - 1)) { | |
return false; | |
} | |
} | |
return true; | |
} | |
private static boolean checkLtoH (String input) { | |
for (int i = 0; i < input.length() - 1; i++) { | |
if (input.charAt(i) - input.charAt(i + 1) != -1) { | |
return false; | |
} | |
} | |
return true; | |
} | |
private static boolean checkHtoL (String input) { | |
for (int i = 0; i < input.length() - 1; i++) { | |
if (input.charAt(i) - input.charAt(i + 1) != 1) { | |
return false; | |
} | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment