Advertisement
sushmoyr

LRC

Jul 22nd, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int table[7][7];
  4. string toBinary(int n)
  5. {
  6.     string s;
  7.     while(n)
  8.     {
  9.         s.push_back((n%2)+'0');
  10.         n/=2;
  11.     }
  12.     reverse(s.begin(),s.end());
  13.     return s;
  14. }
  15. int main()
  16. {
  17.     int temp=0;
  18.     string data,binaryBlock;
  19.     cin>>data;
  20.     for(int i=0; i<data.size(); i++)
  21.     {
  22.         temp=data[i];
  23.         binaryBlock=toBinary(temp);
  24.         for(int j=6,k=binaryBlock.size()-1; j>=0 and k>=0; j--,k--)
  25.         {
  26.             table[i][j]=binaryBlock[k]-48;
  27.         }
  28.     }
  29.  
  30.     string ans="";
  31.     for(int i=0; i<7; i++)
  32.     {
  33.         int countP=0;
  34.         for(int j=0; j<data.size(); j++)
  35.         {
  36.             if(table[j][i])
  37.                 countP++;
  38.         }
  39.         if(countP%2)
  40.             ans+='1';
  41.         else
  42.             ans+='0';
  43.     }
  44.  
  45.     cout<<ans<<endl;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement