sdutacm-数据结构实验之栈一:进制转换

来源:互联网 发布:用手机可以做淘宝客服 编辑:程序博客网 时间:2024/06/09 18:03

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

Time Limit: 1000MS Memory Limit: 65536KB
SubmitStatistic

Problem Description

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

Input

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

Output

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

Example Input

12798

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: AcceptedTake time: 0msTake Memory: 124KBSubmit time: 2017-01-13 09:19:50****************************************************/

 

0 0
原创粉丝点击