Skip to content

Instantly share code, notes, and snippets.

@iamandrewluca
Created March 24, 2016 17:13
Show Gist options
  • Save iamandrewluca/2b7e21f98586bbf60a2c to your computer and use it in GitHub Desktop.
Save iamandrewluca/2b7e21f98586bbf60a2c to your computer and use it in GitHub Desktop.
Chuck Norris Binnary
#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