Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int counter(char* s)
- {
- int cc = 0;
- while (s[cc] != '\0')
- {
- cc++;
- }
- return cc;
- }
- void summ(char* a, char* b, char* c, int max)
- {
- int i;
- char t;
- for (i = max - 1; i >= 0; i--)
- {
- if (a[i] >= 48 && a[i] < 58 && b[i] >= 48 && b[i] < 58)
- {
- c[i] = a[i] + b[i];
- if (c[i] == 113 || c[i] == 114)
- {
- c[i] = a[i] + b[i] - 'A';
- a[i - 1] = a[i - 1] + '1' - '0';
- }
- if (c[i] >= 106 && c[i] <= 112) c[i] = c[i] - ')';
- if (c[i] >= 96 && c[i] <= 105) c[i] = c[i] - '0';
- }
- if ((a[i] >= 65 && a[i] < 72 && b[i] >= 48 && b[i] < 58) || (b[i] >= 65 && b[i] < 72 && a[i] >= 48 && a[i] < 58))
- {
- c[i] = a[i] + b[i]-'0'-'A';
- if (c[i] >=0 && c[i] <=6) c[i] = c[i] + 'A';
- if (c[i] >=7 && c[i] <=15)
- {
- c[i] = c[i] + ')';
- a[i - 1] = a[i - 1] + '1' - '0';
- }
- }
- if (a[i] >= 65 && a[i] <= 71 && b[i] >= 65 && b[i] <= 71)
- {
- c[i] = a[i] + b[i] - 'A' - 'A';
- if (c[i] >= 0 && c[i] <= 6)
- {
- c[i] = c[i] + '3';
- a[i - 1] = a[i - 1] + '1' - '0';
- }
- if (c[i] >= 7 && c[i] <= 12)
- {
- c[i] = c[i] + ':';
- a[i - 1] = a[i - 1] + '1' - '0';
- }
- }
- }
- c[max] = '\0';
- if (c[0] == '0')
- {
- for (i = 1; i < max + 1; i++)
- cout << c[i];
- }
- else
- cout << c;
- }
- void razn(char* d, char* e, char* r,int max)
- {
- int i;
- for (i = max - 1; i >= 0; i--)
- {
- if (d[i] >= 48 && d[i] < 58 && e[i] >= 48 && e[i] < 58)
- {
- if (d[i] >= e[i]) r[i] = (d[i] - '0') - (e[i] - '0') + '0';
- if (d[i] == e[i]) r[i] = '0';
- if (d[i] < e[i])
- {
- d[i - 1] = d[i - 1] - '1' + '0';
- r[i] = (d[i] - '0' + 17) - (e[i] - '0');
- if (r[i] > 9 && r[i] < 17) r[i] = r[i] + '7';
- else r[i] = r[i] + '0';
- }
- }
- if (d[i] >= 65 && d[i] <= 71 && e[i] >= 48 && e[i] <= 57)
- {
- r[i] = d[i] - e[i];
- if (r[i] >= 17 && r[i] <= 23) r[i] = r[i] + '0';
- if (r[i] >= 14 && r[i] <= 16) r[i] = r[i] + ')';
- }
- if ((e[i] >= 65 && e[i] <= 71 && d[i] >= 48 && d[i] <= 57))
- {
- d[i - 1] = d[i - 1] - '1' + '0';
- r[i] = (d[i] - '0' + 17) - (e[i] - '7');
- if (r[i] >= 0 && r[i] <= 9) r[i] = r[i] + '0';
- if (r[i] >= 10 && r[i] <= 16) r[i] = r[i] + '7';
- }
- if (d[i] >= 65 && d[i] <= 71 && e[i] >= 65 && e[i] <= 71)
- {
- if (d[i] >= e[i]) r[i] = d[i] - e[i] + '0';
- if (d[i] < e[i])
- {
- d[i - 1] = d[i - 1] - '1' + '0';
- if (d[i - 1] == 64) d[i - 1] = '9';
- r[i] = d[i] - e[i] + 'H';
- }
- }
- }
- r[max] = '\0';
- if (r[0] == '0')
- {
- for (i = 1; i < max; i++)
- cout << r[i];
- }
- else
- cout << '\n' << r;
- }
- char* zap(char* a, char* b, int s1, int s2)
- {
- int i, j;
- for (i = s2 - 1, j = s1-1; i >= (s2 - s1), j >=0; i--, j--)
- {
- a[i] = a[j];
- }
- for (i = 0; i < (s2 - s1); i++)
- a[i] = '0';
- a[s2] = '\0';
- return a;
- }
- int main()
- {
- setlocale(LC_ALL, "ru");
- char a[20], b[20], d[20], e[20];
- char c[20], r[20];
- int i, s1, s2, max = 0, in1 = 0, in2 = 0, povt = 0,s3,s4;
- gets_s(a);
- gets_s(b);
- s3 = counter(a);
- s4 = counter(b);
- s1 = counter(a);
- s2 = counter(b);
- if (a[0] == '-')
- {
- in1++;
- for (i = 0; i < s1; i++)
- a[i] = a[i + 1];
- }
- if (b[0] == '-')
- {
- in2++;
- for (i = 0; i < s2; i++)
- b[i] = b[i + 1];
- }
- for (i = s1 - 1; i >= 0; i--)
- {
- a[i + 1] = a[i];
- }
- a[0] = '0';
- a[s1 + 1] = '\0';
- s1 = counter(a);
- s2 = counter(b);
- if (s1 < s2)
- {
- max = s2;
- zap(a, b, s1, s2);
- }
- if (s2 < s1)
- {
- max = s1;
- zap(b, a, s2, s1);
- }
- if (s1 == s2) max = s1;
- for (i = 0; i < max + 1; i++)
- {
- d[i] = a[i];
- e[i] = b[i];
- }
- s1 = counter(a);
- s2 = counter(b);
- if (s1 == s2)
- {
- for (i = 0; i < s1; i++)
- {
- if (a[i] == b[i]) povt++;
- }
- }
- if (a[0] != '+' && a[0] != '-' && b[0] != '+' && b[0] != '-'&& d[0] != '+' && d[0] != '-' && e[0] != '+' && e[0] != '-'&&in1==0&&in2==0)
- {
- if (s3 < s4)
- {
- cout << "summ:"; summ(b, a, c, max);
- }
- else if (s3 >= s4)
- {
- cout << "summ:"; summ(a, b, c, max);
- }
- if (s3 < s4)
- {
- cout << "\nrazn:-"; razn(e, d, r, max);
- }
- else if (s3 > s4)
- {
- cout << "\nrazn:"; razn(d, e, r, max);
- }
- else if (s3 == s4 && d[1] > e[1])
- {
- cout << "\nrazn:"; razn(d, e, r, max);
- }
- else if (s3 == s4 && d[1] < e[1])
- {
- cout << "\nrazn:-"; razn(e, d, r, max);
- }
- else if (s1 == s2 && povt == s1) cout << "\nrazn:0";
- else cout << "\nrazn:"; razn(d, e, r, max);
- }
- if (a[0] != '+' && a[0] != '-' && in2==1&&in1==0)
- {
- if (s3 < s4)
- {
- cout << "\nsumm:-"; razn(e, d, r, max);
- }
- else if (s3 > s4)
- {
- cout << "\nsumm:"; razn(d, e, r, max);
- }
- else if (s3 == s4 && d[1] > e[1])
- {
- cout << "\nsumm:"; razn(d, e, r, max);
- }
- else if (s3 == s4 && d[1] < e[1])
- {
- cout << "\nsumm:-"; razn(e, d, r, max);
- }
- else if (s1 == s2 && s1 == povt) cout << "\nsumm:0";
- cout << "\nrazn:"; summ(a, b, c, max);
- }
- if (b[0] != '+' && b[0] != '-' && in1 == 1&&in2==0)
- {
- if (s3 < s4)
- {
- cout << "\nsumm:"; razn(e, d, r, max);
- }
- else if (s3 > s4)
- {
- cout << "\nsumm:-"; razn(d, e, r, max);
- }
- else if (s3 == s4 && d[1] > e[1])
- {
- cout << "\nsumm:-"; razn(d, e, r, max);
- }
- else if (s3 == s4 && d[1] < e[1])
- {
- cout << "\nsumm:"; razn(e, d, r, max);
- }
- else if (s1 == s2 && s1 == povt) cout << "\nsumm:0";
- cout << "\nrazn:-"; summ(a, b, c, max);
- }
- if (in1 == 1 && in2 == 1)
- {
- cout << "summ:-"; summ(a, b, c, max);
- if (s3 < s4)
- {
- cout << "\nrazn:"; razn(e, d, r, max);
- }
- else if (s3 > s4)
- {
- cout << "\nrazn:-"; razn(d, e, r, max);
- }
- else if (s3 == s4 && d[1] > e[1])
- {
- cout << "\nrazn:-"; razn(d, e, r, max);
- }
- else if (s3 == s4 && d[1] < e[1])
- {
- cout << "\nrazn:"; razn(e, d, r, max);
- }
- else if(s1==s2&&s1==povt) cout << "\nrazn:0";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement