用栈的思想把进制数输出,进制数恰好是逆序,进栈出栈
数据结构实验之栈一:进制转换
Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
输入一个十进制整数,将其转换成对应的R(2<=R<=9)进制数,并输出。
输入
第一行输入需要转换的十进制数;
第二行输入R。
第二行输入R。
输出
输出转换所得的R进制数。
示例输入
1279 8
示例输出
2377
提示
来源
示例程序
- 提交
- 状态
- 讨论
#include <iostream> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <algorithm> using namespace std; int main() { int n,m,i,j,k,t; int top,st[200]; while(~scanf("%d %d",&n,&m)) { top=0; while(n!=0) { st[top++]=n%m; n/=m; } while(top!=0) { printf("%d",st[--top]); } printf("\n"); } return 0; }