Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #include <iostream>
  2. #define dim 1001
  3. using namespace std;
  4. int n, p, suma=0, b, c;
  5. struct Stiva
  6. {
  7. int st[dim], top;
  8. int Empty()
  9. {
  10. return top==-1;
  11. }
  12. int Full()
  13. {
  14. return top==dim-1;
  15. }
  16. void Init()
  17. {
  18. top=-1;
  19. }
  20. void Push10(int x, int p)
  21. {
  22. if(!Full())
  23. st[++top]=x*p;
  24. }
  25. void Pushc(int x, int c)
  26. {
  27. if(!Full())
  28. st[++top]=x%c;
  29. }
  30. void Pop()
  31. {
  32. if(!Empty())
  33. top--;
  34. }
  35. int Front()
  36. {
  37. return st[top];
  38. }
  39. };
  40. int main()
  41. {
  42. Stiva s;
  43. cin>>n>>b>>c;
  44. s.Init();p=1;
  45. while(n>0)
  46. {
  47. s.Push10(n%10, p);
  48. p=p*b;
  49. n/=10;
  50. }
  51. while(!s.Empty())
  52. {
  53. suma+=s.Front();
  54. s.Pop();
  55. }
  56. while(suma)
  57. {
  58. s.Pushc(suma, c);
  59. suma/=c;
  60. }
  61. while(!s.Empty())
  62. {
  63. cout<<s.Front();
  64. s.Pop();
  65. }
  66. return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement