题目连接: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(短除法进制转换)的更多相关文章

  1. NUMBER BASE CONVERSION(进制转换)

    Description Write a program to convert numbers in one base to numbers in a second base. There are 62 ...

  2. poj 1220 NUMBER BASE CONVERSION

    NUMBER BASE CONVERSION Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5976   Accepted: ...

  3. POJ 1220 NUMBER BASE CONVERSION(较复杂的进制转换)

    题目链接 题意 : 给你一个a进制的数串s,让你转化成b进制的输出. A = 10, B = 11, ..., Z = 35, a = 36, b = 37, ..., z = 61,0到9还是原来的 ...

  4. (高精度运算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_ ...

  5. 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 ...

  6. POJ 3191 The Moronic Cowmpouter(进制转换)

    题目链接 题意 : 将一个10进制整数转化为-2进制的数. 思路 :如果你将-2进制下的123转化为十进制是1*(-2)^2+2*(-2)^1+3*(-2)^0.所以十进制转化为-2进制就是一个逆过程 ...

  7. POJ 1220 大数字的进制转换,偷下懒,用java

    题意为进制转换,Java的大数类就像是作弊 import java.math.BigInteger; import java.util.Scanner; public class Main { pub ...

  8. POJ 2305:Basic remains 进制转换

    Basic remains Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5221   Accepted: 2203 Des ...

  9. POJ 2635 The Embarrassed Cryptographer (千进制,素数筛,同余定理)

    The Embarrassed Cryptographer Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15767   A ...

随机推荐

  1. 基于visual Studio2013解决面试题之1402选择排序

     题目

  2. PAT 1002 Hello World for U (20)

    Given any string of N (>=5) characters, you are asked to form the characters into the shape of U. ...

  3. 在SharePoint 2013 中使用文档库Scheduling (计划公布功能)

    本文讲述在SharePoint2013 中使用文档库Scheduling (计划公布功能)的步骤和注意的事项. 文档库Scheduling (计划公布功能) 用于设定当文档通过审批后特定的时间区间内才 ...

  4. linux shell种类

    1.shell 种类 目前我们的 Linux (以 CentOS 5.x 为例) 有多少我们可以使用的 shells 呢? 你可以检查一下 /etc/shells 这个文件,至少就有底下这几个可以用的 ...

  5. 基于visual Studio2013解决面试题之0802数字最多元素

     题目

  6. POJ 2594 Treasure Exploration(最小路径覆盖变形)

    POJ 2594 Treasure Exploration 题目链接 题意:有向无环图,求最少多少条路径能够覆盖整个图,点能够反复走 思路:和普通的最小路径覆盖不同的是,点能够反复走,那么事实上仅仅要 ...

  7. css3 animation动画事件

    当使用css3时,会遇到利用@keyframes来定义动画事件,利用以下3个事件,能够捕捉当前元素的动画: AnimationEnd //动画结束时 AnimationStart  //动画開始 An ...

  8. android用canvas绘制两种波纹效果

     波形效果有几种不同的呈现形式,比如从中间向四周散开的波形,也就是熟知的水涟漪:还有上下波动的曲线,像五线谱等.英文中可以称作Wave或者Ripple,所以暂且叫它们WaveView.WaveLayo ...

  9. 10个优秀的 HTML5 &amp; CSS3 下拉菜单制作教程

    下拉菜单是一个非经常见的效果.在站点设计中被广泛使用.通过使用下拉菜单.设计者不仅能够在站点设计中营造出色的视觉吸引力,但也能够为站点提供了一个有效的导航方案.使用 HTML5 和 CSS3 能够更e ...

  10. 使用JDK自带的工具将中文转换为ascii码

    有时候在MyEclipse中,文件只能保存为“ISO-8859-1”的类型,而这种类型的文件时无法保存中文数据的,那么我们只能将中文数据经过Unicode编码才能往文件中保存,这里可以使用JDK自带的 ...