Guest User

Untitled

a guest
Jan 23rd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <algorithm>
  4. #include <vector>
  5. #include <stack>
  6. #include <queue>
  7. #include <string>
  8. #include <math.h>
  9. using namespace std;
  10.  
  11. void main()
  12. {
  13.     int k,l,m;
  14.     cin >> k >> l >> m;
  15.  
  16.     queue<int> q;
  17.     if (m==0) q.push(0);
  18.  
  19.     while(m!=0)
  20.     {
  21.         q.push(m%l);
  22.         m/=l;
  23.     }
  24.  
  25.     int n=0;
  26.     int b=1;
  27.     while(q.empty()==false)
  28.     {
  29.         int d=q.front();
  30.         if (d>=k)
  31.         {
  32.             cout << "WTF?";
  33.             return;
  34.         }
  35.         n+=b*d;
  36.         b*=k;
  37.  
  38.         q.pop();
  39.     }
  40.  
  41.     cout << n;
  42. }
Add Comment
Please, Sign In to add comment