Advertisement
hugol

Untitled

Nov 23rd, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. // Read inputs from stdin. Write outputs to stdout.
  2.  
  3. #include <iostream>
  4. #include <string>
  5. #include <sstream>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.     string str;
  12.     getline(cin, str);
  13.    
  14.     char p = 64; // 7th bit
  15.     int what = ((str.c_str()[0] & p)!=0); // what is going 1st
  16.     int howmany = 0; // how many of 'what'
  17.        
  18.     for (int n=0; n<str.length(); n++)
  19.     {
  20.         for (int i=0; i<7; i++)
  21.         {
  22.             if (((str.c_str()[n] & p)!=0) != what)
  23.             {
  24.                 if (what==0)
  25.                 {
  26.                     cout << "00 ";
  27.                 } else
  28.                 {
  29.                     cout << "0 ";
  30.                 }
  31.                
  32.                 for (int ih = 0; ih < howmany; ih++)
  33.                 {
  34.                     cout << "0";
  35.                 }
  36.                 cout << " ";
  37.                
  38.                 what = (str.c_str()[n] & p)!=0;
  39.                 howmany = 1;
  40.                
  41.             }
  42.             else
  43.             {
  44.                 howmany++;
  45.             }
  46.             p = p >> 1; // move bit
  47.         }
  48.         p = 64; // 7th bit
  49.     }
  50.    
  51.     if (what==0)
  52.     {
  53.         cout << "00 ";
  54.     } else
  55.     {
  56.         cout << "0 ";
  57.     }
  58.                
  59.     for (int ih = 0; ih < howmany; ih++)
  60.     {
  61.         cout << "0";
  62.     }
  63.            
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement