Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #define dim 1001
- using namespace std;
- int n, p, suma=0, b, c;
- struct Stiva
- {
- int st[dim], top;
- int Empty()
- {
- return top==-1;
- }
- int Full()
- {
- return top==dim-1;
- }
- void Init()
- {
- top=-1;
- }
- void Push10(int x, int p)
- {
- if(!Full())
- st[++top]=x*p;
- }
- void Pushc(int x, int c)
- {
- if(!Full())
- st[++top]=x%c;
- }
- void Pop()
- {
- if(!Empty())
- top--;
- }
- int Front()
- {
- return st[top];
- }
- };
- int main()
- {
- Stiva s;
- cin>>n>>b>>c;
- s.Init();p=1;
- while(n>0)
- {
- s.Push10(n%10, p);
- p=p*b;
- n/=10;
- }
- while(!s.Empty())
- {
- suma+=s.Front();
- s.Pop();
- }
- while(suma)
- {
- s.Pushc(suma, c);
- suma/=c;
- }
- while(!s.Empty())
- {
- cout<<s.Front();
- s.Pop();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement