1252进制转换
2017-08-20 14:38
197 查看
进制转换
Problem Description
输入一个十进制数N,将它转换成R进制数输出。
Input
输入数据包含多个测试实例,每个测试实例包含两个整数N(32位整数)和R(2<=R<=16, R != 10)。
Output
为每个测试实例输出转换后的数,每个输出占一行。如果R大于10,则对应的数字规则参考16进制(比如,10用A表示,等等)。
Example Input
Example Output
Problem Description
输入一个十进制数N,将它转换成R进制数输出。
Input
输入数据包含多个测试实例,每个测试实例包含两个整数N(32位整数)和R(2<=R<=16, R != 10)。
Output
为每个测试实例输出转换后的数,每个输出占一行。如果R大于10,则对应的数字规则参考16进制(比如,10用A表示,等等)。
Example Input
7 2 23 12 -4 3
Example Output
111 1B -11
#include<iostream> #include<stack> using namespace std; int main() { int n,r; while(cin>>n>>r) { stack<char>S; if(n==0) { cout<<"0"<<endl;//0的任何进制都是0 continue; }else if(n<0) { cout<<"-";//如果是负数,提前输出符号,并对其绝对值进行处理,同正数 n*=-1; } int t; while(n) { t=n%r; if(t<10) { t+='0'; S.push(t); } else { t=t+'A'-10; S.push(t); } n/=r; } while(!S.empty()) { cout<<S.top(); S.pop(); } cout<<endl; } return 0; }
相关文章推荐
- SDUT 1252 进制转换
- 进制转换 SDUT 1252
- sdut1252 进制转换
- SDUT—1252(进制转换)
- SDUT 1252 进制转换
- SDUT 1252 进制转换
- 进制转换 sdutoj1252(模拟手写栈2333333)
- 山理工 1252 进制转换
- SDUT 1252----进制转换(栈)
- SDUT 1252 - 进制转换
- sdut 1252 进制转换
- 1252 进制转换
- SDUT 1252 进制转换
- 进制转换---1252
- 山东理工大学ACM平台题答案关于C语言 1252 进制转换
- sdut oj1252 进制转换(栈)
- 2031——进制转换
- 任意进制转换!!!
- 【学习笔记】〖九度OJ〗题目1138:进制转换
- hdu 2031 进制转换