poj 1220 NUMBER BASE CONVERSION(短除法进制转换)
题目连接:1220 NUMBER BASE CONVERSION
题目大意:给出两个进制oldBase 和newBase, 以及以oldBase进制存在的数。要求将这个oldBase进制的数转换成newBase进制的数。
解题思路:短除法,只不过时直接利用了高精度的除法运算, 并且将以前默认的*10换成的*oldBase。
#include <stdio.h>
#include <string.h>
const int N = 1005;
int newBase, oldBase, n, cnt, num[N];
char str[N]; int getnum(char c) {
if (c >= '0' && c <= '9')
return c - '0';
else if (c >= 'A' && c <= 'Z')
return c - 'A' + 10;
else
return c - 'a' + 36;
} char getchar(int c) {
if (c >= 0 && c <= 9)
return '0' + c;
else if (c >= 10 && c < 36)
return 'A' + c - 10;
else
return 'a' + c - 36;
} void change() {
memset(num, 0, sizeof(num));
n = strlen(str);
for (int i = 0; i < n; i++)
num[i] = getnum(str[i]);
} void solve() {
int flag = 1;
memset(str, 0, sizeof(str));
cnt = 0; while (flag) {
int t = 0, k;
flag = 0;
for (int i = 0; i < n; i++) {
k = num[i] + t * oldBase;
num[i] = k / newBase;
if (num[i]) flag = 1;
t = k % newBase;
}
str[cnt++] = getchar(t);
}
} int main() {
int cas;
scanf("%d", &cas);
while (cas--) {
scanf("%d%d%s", &oldBase, &newBase, str); printf("%d %s\n", oldBase, str); change();
solve(); printf("%d ", newBase);
for (int i = cnt - 1; i >= 0; i--)
printf("%c", str[i]);
printf("\n");
if (cas) printf("\n");
}
return 0;
}
poj 1220 NUMBER BASE CONVERSION(短除法进制转换)的更多相关文章
- NUMBER BASE CONVERSION(进制转换)
Description Write a program to convert numbers in one base to numbers in a second base. There are 62 ...
- poj 1220 NUMBER BASE CONVERSION
NUMBER BASE CONVERSION Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5976 Accepted: ...
- POJ 1220 NUMBER BASE CONVERSION(较复杂的进制转换)
题目链接 题意 : 给你一个a进制的数串s,让你转化成b进制的输出. A = 10, B = 11, ..., Z = 35, a = 36, b = 37, ..., z = 61,0到9还是原来的 ...
- (高精度运算4.7.26)POJ 1220 NUMBER BASE CONVERSION(高精度数的任意进制的转换——方法:ba1----->10进制----->ba2)
package com.njupt.acm; import java.math.BigInteger; import java.util.Scanner; public class POJ_1220_ ...
- PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) (进制转换,回文数)
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
- POJ 3191 The Moronic Cowmpouter(进制转换)
题目链接 题意 : 将一个10进制整数转化为-2进制的数. 思路 :如果你将-2进制下的123转化为十进制是1*(-2)^2+2*(-2)^1+3*(-2)^0.所以十进制转化为-2进制就是一个逆过程 ...
- POJ 1220 大数字的进制转换,偷下懒,用java
题意为进制转换,Java的大数类就像是作弊 import java.math.BigInteger; import java.util.Scanner; public class Main { pub ...
- POJ 2305:Basic remains 进制转换
Basic remains Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5221 Accepted: 2203 Des ...
- POJ 2635 The Embarrassed Cryptographer (千进制,素数筛,同余定理)
The Embarrassed Cryptographer Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 15767 A ...
随机推荐
- iTunes Store:隐藏和取消隐藏已购项目
使用 Mac 或 PC 上的 iTunes 来隐藏或取消隐藏已购项目. 如何隐藏已购项目 在 Mac 或 PC 上打开 iTunes. 从 Store 菜单中,选取商店 > 登录,然后输入您的 ...
- NET Core R2跑Hello World
在CentOS 7上安装.NET Core R2跑Hello World 前言 在上个月.NET Core出了最新版本预览版,只是在Window系统上试验了一下.原本想等发布正式版的时候在linux系 ...
- 《WCF技术剖析》博文系列汇总[持续更新中]
原文:<WCF技术剖析>博文系列汇总[持续更新中] 近半年以来,一直忙于我的第一本WCF专著<WCF技术剖析(卷1)>的写作,一直无暇管理自己的Blog.在<WCF技术剖 ...
- 网页内容的html标签补全和过滤的两种方法
网页内容的html标签补全和过滤的两种方法: 假设你的网页内容的html标签显示不全,有些表格标签不完整而导致页面混乱,或者把你的内容之外的局部html页面给包括进去了,我们能够写个函数方法来补全ht ...
- <转载>如果在浏览器网页标题栏左侧加自定义小图标
效果如下: 首先制作一个16*16像素的ico格式的图片,命名为:favicon.ico,然后在网站head标签直接加入: <link rel="icon" href=&qu ...
- 关于android的nfc问题
最近在研究android的nfc问题 首先再网上有很多关于android nfc 读写的问题,但是大多数都是关于Mifare Classic类型卡的读写,我百试不得骑解,于是自己写了一些程序供大家参考 ...
- Windows Azure入门教学系列 (九):Windows Azure 诊断功能
本文是Windows Azure入门教学的第九篇文章. 本文将会介绍如何使用Windows Azure 诊断功能.跟部署在本地服务器上的程序不同,当我们的程序发布到云端之后,我们不能使用通常的调试方法 ...
- paip.php 配置ZEND DEBUGGER 断点调试for cli..
paip.php 配置ZENDDEBUGGER 断点调试for cli.. 作者Attilax , EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http:/ ...
- HDU4549 M斐波那契数
M斐波那契数列 题目分析: M斐波那契数列F[n]是一种整数数列,它的定义例如以下: F[0] = a F[1] = b F[n] = F[n-1] * F[n-2] ( n > 1 ) 如今给 ...
- Net Core-Razor
几行代码解决Razor中的嵌套if语句 MVC开发中,经常会遇到在razor中插入简单的逻辑判断. @if (clientManager.IsAdmin) { if (!Model.Topic.Top ...