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

来源:互联网 发布:log4j2连接数据库 编辑:程序博客网 时间:2024/05/22 07:01

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

Time Limit: 1000MS Memory Limit: 65536KB
SubmitStatistic

Problem Description

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

Input

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

Output

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

Example Input

12798

Example Output

2377

Hint

01#include<iostream>
02#include<stack>
03using namespace std;
04int main()
05{
06    intn,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    return0;
24}
25 
26 
27/***************************************************
28User name: jk160618郭衣鹏
29Result: Accepted
30Take time: 0ms
31Take Memory: 200KB
32Submit time: 2017-10-07 16:29:07
33****************************************************/
原创粉丝点击