Skip to content

Instantly share code, notes, and snippets.

@wingyplus
Created June 28, 2011 16:26
Show Gist options
  • Save wingyplus/1051525 to your computer and use it in GitHub Desktop.
Save wingyplus/1051525 to your computer and use it in GitHub Desktop.
Problem A. License plate
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