Tsinsen A1124 进制转换
2016-04-05 18:56
288 查看
http://oj.tsinsen.com/A1124
分析:又是一道进制转换题,这次考的是负进制,基本思路和除K取余法是相通的,唯一不同的就是如果算出来这一位的系数是负的,那就要向上一位借一。
代码:
#include "bits/stdc++.h" using namespace std; int N, R, Bit, Out[1050]; int main() { scanf("%d%d", &N, &R); printf("%d=", N); while (N) { int q = N / R; q += (N < R * q); Out[Bit++] = N - R * q; N = q; } for (int i = Bit - 1; i >= 0; --i) if (Out[i] > 9) printf("%c", 'A' + Out[i] - 10); else printf("%d", Out[i]); printf("(base%d)\n", R); return 0; }
相关文章推荐
- Scripts after the Linux server installation
- Activity之间使用intent传递大量数据带来问题总结
- imx6 板卡移植官方yocto版本(2_定制系统)
- linux文件系统介绍
- 构建之法:第四章读后感
- 求长方柱的体积和表面积
- imx6 板卡移植官方yocto版本(1_安装环境)
- 20160405_整理
- nginx字体文件配置
- 四个输出消息的 NASM 汇编函数
- 第五周作业。
- 《构建之法》第四章读后感
- 顺时针打印矩阵
- 读《构建之法》第四章有感
- 成员变量与局部变量
- opencv之Mat图像左右移
- Codeforces Round #251(Div. 2) 439A. Devu, the Singer and Churu, the Joker 水题
- jquery 1.11 attr("disabled" 无效
- String类
- 多线程使用总结