Advertisement
savrasov

itoj

Jul 22nd, 2017
422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int ans[100000], h;
  6.  
  7. void umn(int a, int base)
  8. {
  9.     int c = 0, t;
  10.     for (int i = 0; i < h || c; i++)
  11.     {
  12.         if (i >= h) h++;
  13.         t = ans[i] * a + c;
  14.         ans[i] = t % base;
  15.         c = t / base;
  16.     }
  17. }
  18.  
  19. void pls(int a, int base)
  20. {
  21.     int c = 0, t;
  22.     if (!h) h++;
  23.     ans[0] += a;
  24.     for (int i = 0; i < h || c; i++)
  25.     {
  26.         if (i >= h) h++;
  27.         t = ans[i] + c;
  28.         c = t / base;
  29.         ans[i] = t % base;
  30.     }
  31. }
  32.  
  33. int main()
  34. {
  35.     int bases, basef;
  36.     char i;
  37.     cin >> bases >> basef >> i;
  38.     for (;;)
  39.     {
  40.         pls(((i > '9') ? i - 'A' + 10 : i - '0'), basef);
  41.         if (cin >> i) umn(bases, basef);
  42.         else break;
  43.     }
  44.     for (int i = h - 1; i > -1; i--)
  45.         cout << (char)((ans[i] > 9) ? ans[i] - 10 + 'A' : ans[i] + '0');
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement