Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int bin(string n)
  4. {
  5. string num = n;
  6. int dec_value = 0;
  7. int base = 1;
  8. int len = num.length();
  9. for (int i = len - 1; i >= 0; i--)
  10. {
  11. if (num[i] == '1')
  12. dec_value += base;
  13. base = base * 2;
  14. }
  15. return dec_value;
  16. }
  17. int main()
  18. {
  19. int t;
  20. cin>>t;
  21. while(t--)
  22. {
  23. string s,s1;
  24. int a,b,cnt=0;
  25. cin>>s>>s1;
  26. a=bin(s);
  27. b=bin(s1);
  28. while(b!=0)
  29. {
  30. int U = a^b;
  31. int V = a&b;
  32. a = U;
  33. b = V * 2;
  34. cnt++;
  35. }
  36. cout<<cnt<<endl;
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement