Created
June 4, 2016 08:54
-
-
Save junk0612/1a057f55504b1f0dc0e3ef09235f3f1e to your computer and use it in GitHub Desktop.
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
import java.util.Set; | |
import java.util.HashSet; | |
import java.util.TreeSet; | |
public class Main { | |
public String solve(String input) { | |
String[] inputs = input.split(":"); | |
char c = inputs[1].charAt(0); | |
Set<Character> set = new HashSet<>(); | |
for (char s: inputs[0].toCharArray()) { | |
int i = s - '0'; | |
set.add(c); | |
if ((c - 'A') % 8 == i % 8) { | |
c--; | |
if (c < 'A') { | |
c = 'H'; | |
} | |
} | |
else if (c - 'A' + 1 == i) { | |
c++; | |
if (c > 'H') { | |
c = 'A'; | |
} | |
} | |
} | |
set.add(c); | |
StringBuilder builder = new StringBuilder(); | |
for (char s: "ABCDEFGH".toCharArray()) { | |
if (set.add(s)) { | |
builder.append(s); | |
} | |
} | |
String str = builder.toString(); | |
set = new TreeSet<>(); | |
for (char x: str.toCharArray()) { | |
for (char s: inputs[0].toCharArray()) { | |
int i = s - '0'; | |
if ((x - 'A') % 8 == i % 8) { | |
x--; | |
if (x < 'A') { | |
x = 'H'; | |
} | |
} else if (x - 'A' + 1 == i) { | |
x++; | |
if (x > 'H') { | |
x = 'A'; | |
} | |
} | |
} | |
set.add(x); | |
} | |
builder = new StringBuilder(); | |
for (char x: set) { | |
builder.append(x); | |
} | |
return builder.toString(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment