Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int des9(char* s3, int cc)
- {
- int i; int des = 0;
- for (i = 1; i < cc; i++)
- {
- des += (s3[i] - '0') * pow(3, cc - i - 1);
- }
- return des;
- }
- int counter(char* s)
- {
- int cc = 0;
- while (s[cc] != '\0')
- {
- cc++;
- }
- return cc;
- }
- char *zapol(char* a, int s1)
- {
- int i, j;
- for (i = s1 - 1, j = 8; i > 0; i--, j--)
- {
- a[j] = a[i];
- }
- for (i = 1; i <= (9 - s1); i++)
- {
- a[i] = '0';
- }
- a[9] = '\0';
- return a;
- }
- char* prisv(char* a,char *c)
- {
- int i;
- if (a[0] == '+')
- {
- for (i = 0; i < 9; i++)
- c[i] = a[i + 1];
- }
- if (a[0] == '-')
- {
- for (i = 1; i < 9; i++)
- {
- if (a[i] == '0') c[i - 1] = '1';
- else if (a[i] == '1') c[i - 1] = '0';
- c[8] = '\0';
- }
- }
- return c;
- }
- int *summ(char* c, char* d, int* e, char* a, char* b, int mod1, int mod2)
- {
- int i;
- for (i = 7; i >= 0; i--)
- {
- e[i] = (c[i] - '0') + (d[i] - '0');
- if (e[i] == 2)
- {
- e[i] = 0;
- if (i == 0) break;
- c[i - 1] = c[i - 1] + 1;
- }
- if (e[i] == 3)
- {
- e[i] = 1;
- if (i == 0) break;
- c[i - 1] = c[i - 1] + 1;
- }
- }
- if ((a[0] == '-' && (abs(mod1) < abs(mod2))) || (b[0] == '-' && (abs(mod1) > abs(mod2))) || ((a[0] == '-' && b[0] == '-')))
- {
- e[7] = e[7] + 1;;
- for (i = 7; i >= 0; i--)
- {
- if (e[i] == 2)
- {
- e[i] = 0;
- e[i - 1] = e[i - 1] + 1;
- }
- if (e[i] == 3)
- {
- e[i] = 1;
- e[i - 1] = e[i - 1] + 1;
- }
- }
- }
- return e;
- }
- int main()
- {
- int i, s1, s2,j,k=0,mod1,mod2;
- char a[25], b[25], c[25], d[25];
- int e[25];
- cin >> a >> b;
- s1 = counter(a);
- s2 = counter(b);
- mod1 = des9(a, s1);
- mod2 = des9(b, s2);
- if (s1 > 8 || s2 > 8) return 0;
- if (s1 == s2)
- {
- for (i = 0; i < s1; i++)
- {
- if (a[i] == b[i]) k++;
- if ((a[0] != b[0]) && (k == (s1 - 1)))
- {
- cout << "0";
- return 0;
- }
- }
- }
- if (s1 < 9)
- zapol(a, s1);
- if (s2 < 9)
- zapol(b, s2);
- prisv(a, c);
- prisv(b, d);
- summ(c, d, e, a, b, mod1, mod2);
- if (e[0] == 1)
- {
- for (i = 1; i < 8; i++)
- {
- if (e[i] == 0) e[i] = 1;
- else if (e[i] == 1) e[i] = 0;
- }
- for (i = 0; i < 8; i++)
- cout << e[i];
- return 0;
- }
- for (i = 0; i < 8; i++)
- cout << e[i];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement