Guest User

Untitled

a guest
Jan 23rd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 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.     if (k>l || m<0 || k<=1 || l<=1)
  17.     {
  18.         cout << "WTF?";
  19.         return;
  20.     }
  21.  
  22.     queue<int> q;
  23.     if (m==0) q.push(0);
  24.  
  25.     while(m!=0)
  26.     {
  27.         q.push(m%l);
  28.         m/=l;
  29.     }
  30.  
  31.     int n=0;
  32.     int b=1;
  33.     while(q.empty()==false)
  34.     {
  35.         int d=q.front();
  36.         if (d>=k)
  37.         {
  38.             cout << "WTF?";
  39.             return;
  40.         }
  41.         n+=b*d;
  42.         b*=k;
  43.  
  44.         q.pop();
  45.     }
  46.  
  47.     cout << n;
  48. }
Add Comment
Please, Sign In to add comment