Created
March 24, 2016 17:13
-
-
Save iamandrewluca/2b7e21f98586bbf60a2c to your computer and use it in GitHub Desktop.
Chuck Norris Binnary
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
#include <iostream> | |
#include <string> | |
#include <vector> | |
#include <algorithm> | |
#include <bitset> | |
using namespace std; | |
/** | |
* Auto-generated code below aims at helping you parse | |
* the standard input according to the problem statement. | |
**/ | |
int main() | |
{ | |
string MESSAGE; | |
getline(cin, MESSAGE); | |
string answer = ""; | |
int last = -1; | |
// Write an action using cout. DON'T FORGET THE "<< endl" | |
// To debug: cerr << "Debug messages..." << endl; | |
for (int i = 0; i < MESSAGE.length(); i++) { | |
bitset<7> bits(MESSAGE[i]); | |
for (int j = 6; j >= 0; j--) { | |
if (bits[j] == last) { | |
answer += "0"; | |
} else { | |
if (last != -1) { | |
answer += " "; | |
} | |
last = bits[j]; | |
if (bits[j]) { | |
answer += "0 0"; | |
} else { | |
answer += "00 0"; | |
} | |
} | |
} | |
} | |
cerr << endl; | |
cout << answer << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment