进制转换

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 63039    Accepted Submission(s): 34261

Problem Description
输入一个十进制数N,将它转换成R进制数输出。
 
Input
输入数据包含多个测试实例,每个测试实例包含两个整数N(32位整数)和R(2<=R<=16, R<>10)。
 
Output
为每个测试实例输出转换后的数,每个输出占一行。如果R大于10,则对应的数字规则参考16进制(比如,10用A表示,等等)。
 
Sample Input
7 2
23 12
-4 3
 
Sample Output
111
1B
-11
 
Author
lcy
 
Source
 
Recommend
lcy   |   We have carefully selected several similar problems for you:  2035 2043 2036 2048 2049 
 
 
ac代码:  (栈思想,先进后出)
 
 
 
 

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define Swap(a,b,t) t=a,a=b,b=t
#define Mem0(x) memset(x,0,sizeof(x))
#define Mem1(x) memset(x,-1,sizeof(x))
#define MemX(x) memset(x,0x3f,sizeof(x));
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f;
const double eps=1e-12;
stack <int> q;
int main()
{
int n,d;
while (cin>>n>>d){
while (!q.empty())
q.pop();
if (n<0){
cout<<"-";
n=-n;
}
else if (!n){
cout<<'0'<<endl;
continue;
}
while (n){
q.push(n%d);
n/=d;
}
while (!q.empty()){
int x=q.top();
if (x>=10)
printf("%c",'A'+x-10);     //cout<<'A'+x-10<<endl;         这个地方有坑,    这里   cout    输出的不是字符,而是整数.
else
cout<<x;
q.pop();
}
cout<<endl;
}
return 0;
}

最新文章

  1. reds Virtual Memory
  2. 这里有个坑---js日期格式yyyy-MM-dd与yyyy/MM/dd
  3. CCNA网络工程师学习进程(3)常规网络设计模型与基本的网络协议
  4. IdTCPServer
  5. .Net中的Socket通讯
  6. Android开发环境搭建(windows OS)之补充
  7. LightOj_1287 Where to Run
  8. jsp 配置MySQL服务器 以及数据的插入和读取
  9. angular popover的触发问题;
  10. javascript 之执行环境-08
  11. toolbar ,textfield,图片拉伸,Bundle
  12. CentOS 6.5 安装MySQL过程
  13. C语言中__attribute__ ((at())绝对定位的应用
  14. Centos7上实现不同网段的服务器文件共享
  15. git pull总是要输入账号和密码
  16. Python 进行查询日志查询条件分析
  17. df 与 du 已使用空间不一致的原因及解决办法
  18. 管理MariaDB
  19. 【死磕 Spring】—— IoC 之加载 BeanDefinition
  20. Rust 阴阳谜题,及纯基于代码的分析与化简

热门文章

  1. PostgreSQL的generate_series函数应用
  2. UVALive 4025 Color Squares(BFS)
  3. poj 3253 Fence Repair (STL优先队列)
  4. 轻松排查线上Node内存泄漏问题
  5. SqlMapConfig.xml配置文件
  6. Vue中better-scroll插件的使用
  7. Elementui 导航组件和Vuejs路由结合
  8. spring使用 hibernate jpa JpaRepository
  9. VC MFC工具栏(CToolBar)控件(转)
  10. Java语言实现简单的登陆注册