Skip to content

Instantly share code, notes, and snippets.

@iamandrewluca
Created March 24, 2016 17:38
Show Gist options
  • Save iamandrewluca/69e03eb75a33cbcedd25 to your computer and use it in GitHub Desktop.
Save iamandrewluca/69e03eb75a33cbcedd25 to your computer and use it in GitHub Desktop.
Chuck binnary 1
#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 = "";
// Write an action using cout. DON'T FORGET THE "<< endl"
// To debug: cerr << "Debug messages..." << endl;
string output = "";
for (int i = 0; i < message.size(); ++i) {
bitset<7> b(message.c_str()[i]);
output += b.to_string();
}
int last = -1;
for (int i = 0; i < output.size(); ++i) {
if (output[i] == last) {
answer += "0";
} else {
if (i != 0) answer += " ";
last = output[i];
if (last == '1') {
answer += "0 0";
} else if (last == '0') {
answer += "00 0";
}
}
}
cerr << output << endl;
cout << answer << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment