jaredec18

Untitled

Sep 13th, 2019
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int m;
  8. cin>>m;
  9. int a[7]={0};
  10. int i=6;
  11. while(m>0)
  12. {
  13. a[i]=m%10;
  14. m=m/10;
  15. i--;
  16. }
  17.  
  18. int p1= a[0]^a[2]^a[4]^a[6];
  19. int p2= a[1]^a[2]^a[5]^a[6];
  20. int p3= a[3]^a[4]^a[5]^a[6];
  21. int error_bit= p3*4+p2*2+p1;
  22. if(error_bit==0)
  23. {
  24. cout<<"your code is correct. The number sent is ";
  25. int number=0;
  26. number= a[2]*8+a[4]*4+a[5]*2+a[6];
  27. cout<<number<<endl;
  28. }
  29. else
  30. {
  31. cout<<"Your code has an error at bit "<<error_bit<<endl;
  32. cout<<"The corrected code is ";
  33.  
  34. if(a[error_bit-1]==0)
  35. a[error_bit-1]=1;
  36. else
  37. a[error_bit-1]=0;
  38. for(i=0;i<7;i++)cout<<a[i];cout<<endl;
  39. cout<<"The number sent is ";
  40. int number=0;
  41. number= a[2]*8+a[4]*4+a[5]*2+a[6];
  42. cout<<number<<endl;
  43. }
  44.  
  45.  
  46. return 0;
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment