-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchuck-norris-v2.java
More file actions
35 lines (32 loc) · 1.18 KB
/
chuck-norris-v2.java
File metadata and controls
35 lines (32 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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 {
/**
* As long as the new bit is the same as the previous bit, output a "0".
* Otherwise (if the new bit differs from the previous bit) end the sequence with " ".
* Then output a "0 0" or "00 0" depending on the new bit (it already includes the first counting "0" for the new bit).
**/
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
char[] MESSAGE = in.nextLine().toCharArray();
//Convert char to bit value
boolean previoutBit = (MESSAGE[0] & 0x40) != 0;
System.out.print(previoutBit ? "0 " : "00 ");
for (char B : MESSAGE)
{
for (char bm = 0x40; bm != 0; bm >>= 1)
{
boolean bit = (B & bm) != 0;
System.out.print((bit == previoutBit) ? "0"
: bit ? " 0 0"
: " 00 0");
previoutBit = bit;
}
}
}
}