Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <bitset>
- #include <vector>
- #include <algorithm>
- using namespace std;
- /**
- * Auto-generated code below aims at helping you parse
- * the standard input according to the problem statement.
- **/
- void chaintobin(vector<int>);
- int main()
- {
- vector<int> bit;
- string MESSAGE;
- getline(cin, MESSAGE);
- for(int i=0; i< MESSAGE.size(); ++i){
- bitset<7> a (MESSAGE[i]);
- for(int j=6; j>=0;--j)
- bit.push_back(a[j]);
- }
- chaintobin(bit);
- cout << endl;
- }
- void chaintobin(vector<int> a){
- int i, count=0,rec=a[6];
- rec= a.front();
- for(vector<int>::iterator i = a.begin()+1; i != a.end();++i)
- {
- if(*i==rec)
- count++;
- else{
- count++;
- /* 1 -> 0 & 0 -> 00 */
- if(rec==1) {cout<< '0' <<" ";}
- else {cout<< "00" <<" ";}
- /* mettre le nombre de 0 ou 1 trouver */
- for(int j=0; j<count; ++j){
- cout<<0;
- }
- rec= *i;
- cout<<" ";
- count=0;
- }
- }
- if(rec==1) {cout<< '0' <<" ";}
- else {cout<< "00" <<" ";}
- for(int j=0; j<=count; ++j){
- cout<<0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement