进制转换
来源:互联网 发布:navicat如何连接mysql 编辑:程序博客网 时间:2024/06/05 02:15
进制转换
TimeLimit: 1000ms Memory limit: 65536K
题目描述
输入一个十进制数N,将它转换成R进制数输出。
输入
输入数据包含多个测试实例,每个测试实例包含两个整数N(32位整数)和R(2<=R<=16,R<>10)。
输出
为每个测试实例输出转换后的数,每个输出占一行。如果R大于10,则对应的数字规则参考16进制(比如,10用A表示,等等)。
示例输入
72
2312
-43
示例输出
111
1B
-11
//模拟栈#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 0x3f3f3f3fusing namespace std;struct node{ char data; node *next;};int main(){ int n,m; node *head,*p; head=new node; while(~scanf("%d %d",&n,&m)) { if(n==0)//注意零 { cout<<0<<endl; } else { if(n<0) { cout<<'-'; n=-n; } int ans; head->next=NULL; while(n) { p=new node; ans=n%m; if(ans>=0&&ans<=9) { p->data=ans+'0'; } else { p->data=ans-10+'A'; } p->next=head->next; head->next=p; n/=m; } p=head->next; while(p) { cout<<p->data; p=p->next; } cout<<endl; } } return 0;}
STL #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 0x3f3f3f3fusing namespace std;int main(){ int n,m; while(~scanf("%d %d",&n,&m)) { if(n==0) { cout<<0<<endl; continue; } if(n<0) { cout<<'-'; n=-n; } stack<char>B; int ans; while(n) { ans=n%m; if(ans>=0&&ans<=9) { B.push(ans+'0'); } else { B.push(ans-10+'A'); } n/=m; } while(!B.empty()) { cout<<B.top(); B.pop(); } cout<<endl; } return 0;}
0 0
- 进制转换,类型转换
- 进制转换(进制转换)
- 进制转换-----十进制转换成二进制
- 进制的转换,八进制转换十六进制
- 进制转换,运算符,类型转换,
- 十进制转换2-9进制转换
- 进制转换
- 无限进制转换
- 进制转换
- 进制转换
- 进制转换
- 【整理】进制转换
- 进制转换
- 七、进制转换
- 进制转换
- 进制转换
- 进制转换
- NotesScript 进制转换
- 安卓LISTVIEW
- PowerDesigner 模型导出图片不清晰的问题
- tomcate 端口号占用,Windows的解决方法
- Linux-管理文件权限和所有权
- GitHub超详细图文攻略 - Git客户端下载安装 GitHub提交修改源码工作流程 Git分支 标签 过滤 Git版本工作流
- 进制转换
- Tomcat6 配置多虚拟主机,多域名绑定一IP
- android开发环境安装与配置
- mybatis 联合查询
- Ext实现waiting提示功能
- 一张帖搞定同学们入学黑马前所有难题
- PNG文件格式详解
- leetcode String to Integer (atoi)
- lua不支持thrift协议