数据结构实验之栈一:进制转换
Time Limit: 1000MS Memory limit: 65536K
题目描述
输入一个十进制整数,将其转换成对应的R(2<=R<=9)进制数,并输出。
输入
第一行输入需要转换的十进制数;
第二行输入R。
第二行输入R。
输出
输出转换所得的R进制数。
示例输入
1279 8
示例输出
2377
提示
来源
示例程序
#include<stdio.h>
#include<stack>
#include<iostream>
using namespace std;
typedef struct
{
int *base;
int *top;
int length;
}Sqstack;
int push(Sqstack *s,int e)
{
*(s->top)=e;
s->top++;
}
int pop(Sqstack *s,int e)
{
e=*(s->top-1);
s->top--;
}
int Gettop(Sqstack *s,int e)
{
e=*(s->top-1);
}
int main()
{
int n,m,z;
stack<int>Q;
scanf("%d%d",&n,&m);
while(n>0)
{
z=n%m;
Q.push(z);
n=n/m;
}
while(!Q.empty())
{
printf("%d",Q.top());
Q.pop();
}
printf("\n");
}