Created
February 2, 2016 21:53
-
-
Save vchatela/557c0a3a09f158cbfffd to your computer and use it in GitHub Desktop.
Codingame : ChuckNorris Solution
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.*; | |
import java.io.*; | |
import java.math.*; | |
/** | |
* Auto-generated code below aims at helping you parse | |
* the standard input according to the problem statement. | |
**/ | |
class Solution { | |
public static void main(String args[]) { | |
Scanner in = new Scanner(System.in); | |
String MESSAGE = in.nextLine(); | |
char[] cArray = MESSAGE.toCharArray(); | |
StringBuilder answer = new StringBuilder(); | |
StringBuilder binaryString = new StringBuilder(); | |
for (char stringChar : cArray) { | |
binaryString.append((String) String.format("%7s", Integer.toBinaryString((int) stringChar)).replace(' ', '0')); | |
} | |
String groups[] = binaryString.toString().split("(?<=1)(?=0)|(?<=0)(?=1)"); | |
int counter = 0; | |
for (String group : groups) { | |
//System.err.println(group); | |
if (group.contains("0")) { | |
answer.append("00 "); | |
} | |
else { | |
answer.append("0 "); | |
} | |
for (int i = 0; i < group.length(); i++) { | |
answer.append("0"); | |
} | |
if (counter < groups.length - 1) { | |
answer.append(" "); | |
counter++; | |
} | |
} | |
System.out.println(answer.toString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment