Advertisement
Guest User

Untitled

a guest
Mar 24th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <bitset>
  4. #include <vector>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. /**
  10. * Auto-generated code below aims at helping you parse
  11. * the standard input according to the problem statement.
  12. **/
  13.  
  14. void chaintobin(vector<int>);
  15.  
  16. int main()
  17. {
  18. vector<int> bit;
  19. string MESSAGE;
  20. getline(cin, MESSAGE);
  21.  
  22. for(int i=0; i< MESSAGE.size(); ++i){
  23. bitset<7> a (MESSAGE[i]);
  24. for(int j=6; j>=0;--j)
  25. bit.push_back(a[j]);
  26. }
  27. chaintobin(bit);
  28. cout << endl;
  29. }
  30.  
  31.  
  32. void chaintobin(vector<int> a){
  33. int i, count=0,rec=a[6];
  34.  
  35. rec= a.front();
  36. for(vector<int>::iterator i = a.begin()+1; i != a.end();++i)
  37. {
  38. if(*i==rec)
  39. count++;
  40. else{
  41. count++;
  42. /* 1 -> 0 & 0 -> 00 */
  43. if(rec==1) {cout<< '0' <<" ";}
  44. else {cout<< "00" <<" ";}
  45.  
  46. /* mettre le nombre de 0 ou 1 trouver */
  47. for(int j=0; j<count; ++j){
  48. cout<<0;
  49. }
  50. rec= *i;
  51. cout<<" ";
  52. count=0;
  53. }
  54.  
  55. }
  56.  
  57. if(rec==1) {cout<< '0' <<" ";}
  58. else {cout<< "00" <<" ";}
  59. for(int j=0; j<=count; ++j){
  60. cout<<0;
  61. }
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement