数据结构实验之栈一:进制转换
Time Limit: 1000MS Memory Limit: 65536KB
Problem Description
输入一个十进制非负整数,将其转换成对应的 R (2 <= R <= 9) 进制数,并输出。
Input
第一行输入需要转换的十进制非负整数;
第二行输入 R。
Output
输出转换所得的 R 进制数。
Example Input
1279 8
Example Output
2377
Hint
Author
1
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<stdlib.h>
#include<stack>
using namespace std;
int main()
{
int n,r;
scanf("%d%d",&n,&r);
stack<int>t;
if(n==0)
printf("0\n");
else
{
while(n>0)
{
int z =n%r;
t.push(z);
n /= r;
}
while(!t.empty())
{
printf("%d",t.top());
t.pop();
}
printf("\n");
}
return 0;
}
/***************************************************
User name: jk160505徐红博
Result: Accepted
Take time: 0ms
Take Memory: 124KB
Submit time: 2017-01-13 09:19:50
****************************************************/

京公网安备 11010502036488号