您的位置:首页 > 理论基础 > 数据结构算法

数据结构——栈与队列进制转换

2017-10-07 16:36 375 查看

数据结构实验之栈与队列一:进制转换

Time Limit: 1000MS
Memory Limit: 65536KB
Submit

Statistic

Problem Description

输入一个十进制非负整数,将其转换成对应的 R (2 <= R <= 9) 进制数,并输出。

Input

第一行输入需要转换的十进制非负整数;

第二行输入 R。

Output

输出转换所得的 R 进制数。

Example Input

1279
8


Example Output

2377


Hint

01
#include<iostream>
02
#include<stack>
03
using
namespace
std;
04
int
main()
05
{
06
    
int

n,m;
07
    
cin>>n>>m;
08
    
stack<
int
>s;
09
    
if
(n==0)
10
    
{
11
        
cout<<
"0"
<<endl;
12
    
}
13
    
while
(n)
14
    
{
15
        
s.push(n%m);
16
        
n=n/m;
17
    
}
18
    
while
(!s.empty())
19
    
{
20
        
cout<<s.top();
21
        
s.pop();
22
    
}
23
    
return

0;
24
}
25
 
26
 
27
/***************************************************
28
User name: jk160618郭衣鹏
29
Result: Accepted
30
Take time: 0ms
31
Take Memory: 200KB
32
Submit time: 2017-10-07 16:29:07
33
****************************************************/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: