Created
March 24, 2016 17:38
-
-
Save iamandrewluca/69e03eb75a33cbcedd25 to your computer and use it in GitHub Desktop.
Chuck binnary 1
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 = ""; | |
// 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