Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #define MAX 100
- using namespace std;
- class Bigint
- {
- int a[MAX];
- int n;
- public:
- Bigint()
- {
- n = 0;
- }
- Bigint(const Bigint& a)
- {
- Bigint b;
- this->n = a.n;
- for (int i = 0; i < a.n; i++)
- this->a[i] = a.a[i];
- }
- Bigint& operator = (Bigint a)
- {
- Bigint b;
- b.n = a.n;
- for (int i = 0; i < a.n; i++)
- b.a[i] = a.a[i];
- return b;
- }
- friend istream& operator >> (istream& in, Bigint &b)
- {
- char a[MAX];
- in.getline(a, MAX - 1);
- b.n = strlen(a);
- for (int i = 0; i < b.n; i++)
- b.a[i] = a[i] - '0';
- return in;
- }
- friend ostream& operator << (ostream &out, Bigint b)
- {
- for (int i = 0; i < b.n; i++)
- {
- out << b.a[i];
- }
- if (b.n == 0) cout << "0";
- out << endl;
- return out;
- }
- int GetSize()
- {
- return n;
- }
- friend Bigint& operator - (Bigint a, Bigint b)
- {
- Bigint c;
- int max = ((a.n > b.n) ? a.n : b.n);
- int n1 = a.n, n2 = b.n;
- int r = 0;
- c.n = max;
- while (n1 && n2)
- {
- if (a.a[n1 - 1] - b.a[n2 - 1] - r < 0)
- {
- c.a[max - 1] = (a.a[n1 - 1] - b.a[n2 - 1] - r) + 10;
- r = 1;
- }
- else
- {
- c.a[max - 1] = (a.a[n1 - 1] - b.a[n2 - 1] - r);
- r = 0;
- }
- max--;
- n1--;
- n2--;
- }
- while (n1)
- {
- if (a.a[n1 - 1] - r < 0)
- {
- c.a[max - 1] = (a.a[n1 - 1] - r) + 10;
- r = 1;
- }
- else
- {
- c.a[max - 1] = (a.a[n1 - 1] - r);
- r = 0;
- }
- max--;
- n1--;
- }
- if (c.a[0] == 0)
- {
- for (int i = 0; i < c.n; i++)
- {
- c.a[i] = c.a[i + 1];
- }
- c.n--;
- }
- return c;
- }
- Bigint div2()
- {
- Bigint b;
- int r = 0;
- int m;
- for (int i = 0; i < n; i++)
- {
- r = r * 10 + a[i];
- m = r / 2;
- r = r - m * 2;
- b.a[i] = m;
- }
- b.n = n;
- if (b.a[0] == 0)
- {
- for (int i = 0; i < b.n; i++)
- {
- b.a[i] = b.a[i + 1];
- }
- b.n--;
- }
- return b;
- }
- Bigint mul2()
- {
- Bigint b;
- int r = 0;
- b.n = n;
- for (int i = n - 1; i >= 0; i--)
- {
- b.a[i] = (a[i] * 2 + r) % 10;
- r = (a[i] * 2 + r) / 10;
- }
- if (r != 0)
- {
- for (int i = b.n; i > 1; i--)
- {
- b.a[i] = b.a[i - 1];
- }
- b.a[0] = r;
- b.n++;
- }
- return b;
- }
- int mod2()
- {
- return (a[n - 1] % 2);
- }
- friend void NhiPhan(Bigint a)
- {
- if (a.n != 0)
- {
- NhiPhan(a.div2());
- cout << a.mod2();
- }
- }
- };
- void main()
- {
- Bigint a;
- cin >> a;
- NhiPhan(a);
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement