任意进制转换


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

Input 

1279
8

Output 

2377

#include
using namespace std;
int main()
{
    stack<int> a;
    // 5/2=2 1;
    // 2/2=1 0;
    // 1/2=0 1;
    int n;
    cin>>n;
    int b;
    cin>>b;

//核心代码


int remainder;
while(n) { remainder=n%b; n=n/b; a.push(remainder); }


while (!a.empty()) { cout<<a.top(); a.pop(); } return 0; } // 讨论0;

相关