Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #include<iostream>
  2. #include<sstream>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. int toInt(string x)
  8. {
  9. stringstream txt;
  10. int a;
  11.  
  12. txt << x;
  13. txt >> a;
  14.  
  15. return a;
  16. }
  17. string toString(int a)
  18. {
  19. stringstream b;
  20. string c;
  21.  
  22. b << a;
  23. b >> c;
  24.  
  25. return c;
  26. }
  27. unsigned int russianPeasantBinary(unsigned int a, unsigned int b) {
  28. unsigned int wynik = 0;
  29. while (b > 0) {
  30. if (b & 1)
  31. wynik += a;
  32. a <<= 1;
  33. b >>= 1;
  34. }
  35. return wynik;
  36. }
  37. int main()
  38. {
  39. string x;
  40. string y;
  41. string ros;
  42. string ost;
  43. int poP;
  44. int pom;
  45. int a;
  46. int liczbaRosyjska;
  47. cin >> x;
  48. cin >> y;
  49.  
  50. int p = x.find(",");
  51.  
  52. x = x.erase(p,1);
  53.  
  54. a = toInt(x);
  55.  
  56. int b;
  57.  
  58.  
  59.  
  60. int m = y.find(",");
  61.  
  62. y = y.erase(m,1);
  63.  
  64. b = toInt(y);
  65.  
  66. poP = (x.size()- p) + (y.size() - m);
  67.  
  68. liczbaRosyjska = russianPeasantBinary(a ,b);
  69.  
  70. ros = toString(liczbaRosyjska);
  71. pom = ros.size() - poP;
  72.  
  73. ros.insert(pom ,",");
  74. cout << ros << endl;
  75.  
  76. return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement