【清澄】A1012. 进制转换3
2013-12-06 16:42
267 查看
将10进制a转化为p进制。
0<=a<=2147483647,2<=p<=36.
2147483647=2^31-1,它是第8个梅森素数哦!
所以要用 long long。
连除取余法。
0<=a<=2147483647,2<=p<=36.
2147483647=2^31-1,它是第8个梅森素数哦!
所以要用 long long。
连除取余法。
#include<cstdio> #include<iostream> #include<algorithm> using namespace std; char ans[100]; int main() { long long n; int p; while(scanf("%I64d%d",&n,&p)!=EOF) { int r=0; if(n==0) { printf("0\n"); continue; } while(n) { int a=n%p; if(a>=0 && a<=9) ans[r++]='0'+a; else { ans[r++]=a-10+'A'; } n=n/p; } for(int i=r-1;i>=0;i--) printf("%c",ans[i]); printf("\n"); } return 0; }
相关文章推荐
- C++内联使用技巧
- 漫谈C语言及如何学习C语言
- 漫谈C语言及如何学习C语言
- 【转】小知识3
- [译]理解对象存储如何工作
- 黑马程序员——Java基本开发环境搭建
- SAP中执行没有权限的事务
- Uevent 上报event事件给上层的详细讲解
- 离开Linux,重回Windows
- Graphics View Framework
- android系统默认设置
- 从Maven仓库中导出 依赖 jar包
- access数据库select查询top时无效的解决办法
- java之Socket传递图片
- Android 9.png图片的制作方法
- ALsa Control 从上层到驱动的详解
- conversion between UTF8 and string
- 排序算法示意图
- [转]推荐net开发cad入门阅读代码片段
- ORA-00911错误及解决方法