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

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

Time Limit: 1000 ms Memory Limit: 65536 KiB

Submit Statistic Discuss

Problem Description

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

Input

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

Output

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

Sample Input

1279
8

Sample Output

2377

Hint

Source

#include <iostream>
#include<string.h>
using namespace std;
int top[10010];
void st(int n,int m)
{
    int i,s=0;
    if(n==0)
        cout<<0<<endl;
    else
    {
        while(n)
        {
            top[s]=n%m;
            n=n/m;
            s++;
        }
        for(i=s-1; i>=0; i--)
            cout<<top[i];
        cout<<endl;
    }
}
int main()
{
    int n,m;
    cin>>n>>m;
    st(n,m);


    return 0;
}

无论是求什么进制,都是用这个模板啦

猜你喜欢

转载自blog.csdn.net/qq_41374539/article/details/81066768