Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int des9(char* s3, int cc)
  4. {
  5. int i; int des = 0;
  6. for (i = 1; i < cc; i++)
  7. {
  8. des += (s3[i] - '0') * pow(3, cc - i - 1);
  9. }
  10. return des;
  11. }
  12. int counter(char* s)
  13. {
  14. int cc = 0;
  15. while (s[cc] != '\0')
  16. {
  17. cc++;
  18. }
  19. return cc;
  20. }
  21. char *zapol(char* a, int s1)
  22. {
  23. int i, j;
  24. for (i = s1 - 1, j = 8; i > 0; i--, j--)
  25. {
  26. a[j] = a[i];
  27. }
  28. for (i = 1; i <= (9 - s1); i++)
  29. {
  30. a[i] = '0';
  31.  
  32. }
  33. a[9] = '\0';
  34. return a;
  35. }
  36. char* prisv(char* a,char *c)
  37. {
  38. int i;
  39. if (a[0] == '+')
  40. {
  41. for (i = 0; i < 9; i++)
  42. c[i] = a[i + 1];
  43. }
  44. if (a[0] == '-')
  45. {
  46. for (i = 1; i < 9; i++)
  47. {
  48. if (a[i] == '0') c[i - 1] = '1';
  49. else if (a[i] == '1') c[i - 1] = '0';
  50. c[8] = '\0';
  51. }
  52. }
  53. return c;
  54. }
  55. int *summ(char* c, char* d, int* e, char* a, char* b, int mod1, int mod2)
  56. {
  57. int i;
  58. for (i = 7; i >= 0; i--)
  59. {
  60. e[i] = (c[i] - '0') + (d[i] - '0');
  61. if (e[i] == 2)
  62. {
  63. e[i] = 0;
  64. if (i == 0) break;
  65. c[i - 1] = c[i - 1] + 1;
  66. }
  67. if (e[i] == 3)
  68. {
  69. e[i] = 1;
  70. if (i == 0) break;
  71. c[i - 1] = c[i - 1] + 1;
  72. }
  73. }
  74. if ((a[0] == '-' && (abs(mod1) < abs(mod2))) || (b[0] == '-' && (abs(mod1) > abs(mod2))) || ((a[0] == '-' && b[0] == '-')))
  75. {
  76. e[7] = e[7] + 1;;
  77. for (i = 7; i >= 0; i--)
  78. {
  79. if (e[i] == 2)
  80. {
  81. e[i] = 0;
  82. e[i - 1] = e[i - 1] + 1;
  83. }
  84. if (e[i] == 3)
  85. {
  86. e[i] = 1;
  87. e[i - 1] = e[i - 1] + 1;
  88. }
  89. }
  90. }
  91. return e;
  92. }
  93. int main()
  94. {
  95. int i, s1, s2,j,k=0,mod1,mod2;
  96. char a[25], b[25], c[25], d[25];
  97. int e[25];
  98. cin >> a >> b;
  99. s1 = counter(a);
  100. s2 = counter(b);
  101. mod1 = des9(a, s1);
  102. mod2 = des9(b, s2);
  103. if (s1 > 8 || s2 > 8) return 0;
  104. if (s1 == s2)
  105. {
  106. for (i = 0; i < s1; i++)
  107. {
  108. if (a[i] == b[i]) k++;
  109. if ((a[0] != b[0]) && (k == (s1 - 1)))
  110. {
  111. cout << "0";
  112. return 0;
  113. }
  114. }
  115. }
  116. if (s1 < 9)
  117. zapol(a, s1);
  118. if (s2 < 9)
  119. zapol(b, s2);
  120. prisv(a, c);
  121. prisv(b, d);
  122. summ(c, d, e, a, b, mod1, mod2);
  123. if (e[0] == 1)
  124. {
  125. for (i = 1; i < 8; i++)
  126. {
  127. if (e[i] == 0) e[i] = 1;
  128. else if (e[i] == 1) e[i] = 0;
  129.  
  130. }
  131. for (i = 0; i < 8; i++)
  132. cout << e[i];
  133. return 0;
  134. }
  135.  
  136. for (i = 0; i < 8; i++)
  137. cout << e[i];
  138. return 0;
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement