您的位置:首页 > 其它

进制转换2

2015-06-09 10:25 363 查看
数据结构实验之栈一:进制转换
TimeLimit: 1000ms Memory limit: 65536K
有疑问?点这里^_^
题目描述
输入一个十进制整数,将其转换成对应的R(2<=R<=9)进制数,并输出。
输入
第一行输入需要转换的十进制数;
第二行输入R。
输出
输出转换所得的R进制数。
示例输入
1279
8
示例输出
2377
#include <map>
#include <set>
#include <cmath>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <vector>
#include <string>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define RR freopen("input.txt","r",stdin)
#define WW freopen("output.txt","w",stdout)
#define INF 0x3f3f3f3f

using namespace std;

int main()
{
int n,m;
cin>>n>>m;

if(n==0)
{
cout<<0<<endl;

}
else
{
if(n<0)
{
cout<<'-';
n=-n;
}
stack<int>B;
while(n)
{
B.push(n%m);
n/=m;
}
while(!B.empty())
{
cout<<B.top();
B.pop();
}
cout<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: