普通的做法,大数除小数。

复杂度o( log(n)*log(n) ),其实就是位数的平方。

NUMBER BASE CONVERSION
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 4913   Accepted: 2246

Description

Write a program to convert numbers in one base to numbers in a second base. There are 62 different digits:
{ 0-9,A-Z,a-z }

HINT: If you make a sequence of base conversions using the output of
one conversion as the input to the next, when you get back to the
original base, you should get the original number.

Input

The
first line of input contains a single positive integer. This is the
number of lines that follow. Each of the following lines will have a
(decimal) input base followed by a (decimal) output base followed by a
number expressed in the input base. Both the input base and the output
base will be in the range from 2 to 62. That is (in decimal) A = 10, B =
11, ..., Z = 35, a = 36, b = 37, ..., z = 61 (0-9 have their usual
meanings).

Output

The
output of the program should consist of three lines of output for each
base conversion performed. The first line should be the input base in
decimal followed by a space then the input number (as given expressed in
the input base). The second output line should be the output base
followed by a space then the input number (as expressed in the output
base). The third output line is blank.

Sample Input

8
62 2 abcdefghiz
10 16 1234567890123456789012345678901234567890
16 35 3A0C92075C0DBF3B8ACBC5F96CE3F0AD2
35 23 333YMHOUE8JPLT7OX6K9FYCQ8A
23 49 946B9AA02MI37E3D3MMJ4G7BL2F05
49 61 1VbDkSIMJL3JjRgAdlUfcaWj
61 5 dl9MDSWqwHjDnToKcsWE1S
5 10 42104444441001414401221302402201233340311104212022133030

Sample Output

62 abcdefghiz
2 11011100000100010111110010010110011111001001100011010010001 10 1234567890123456789012345678901234567890
16 3A0C92075C0DBF3B8ACBC5F96CE3F0AD2 16 3A0C92075C0DBF3B8ACBC5F96CE3F0AD2
35 333YMHOUE8JPLT7OX6K9FYCQ8A
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
using namespace std; char str[];
int num[];
int ans[]; int chg(char c)
{
if( c>=''&&c<='' ) return c-'';
if( c>='A'&&c<='Z' ) return c-'A'+;
if( c>='a'&&c<='z' ) return c-'a'+;
return -;
} char unchg(int x)
{
if(x>=&&x<=) return x+'';
if(x>=&&x<=) return 'A'+x-;
else return 'a'+x-;
} int main()
{
int T;
cin>>T;
while(T--)
{
int from,to;
scanf("%d%d",&from,&to);
scanf("%s",str);
int len=strlen(str);
for(int i=;i<len;i++)
{
num[i] = chg(str[i]);
}
int cnt=;
int wei=;
while( cnt < len )
{
//然后做一次除法
for(int i=cnt;i<len;i++)
{
num[ i+ ] += (num[i]%to)*from;
num[ i ] /= to;
}
ans[ wei++ ] = num[len]/from;
num[len]=;
for(int i=cnt;i<len;i++)
{
if(num[i]==) cnt++;
else break;
}
}
printf("%d %s\n",from,str);
printf("%d ",to);
for(int i=wei-;i>=;i--)
{
printf("%c",unchg(ans[i]));
}
printf("\n\n");
}
return ;
}

大数进制转换 poj1220的更多相关文章

  1. POJ1220(大数进制转换)

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

  2. hdu-1877(大数+进制转换)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1877 思路:注意考虑0,0的情况. #include<iostream> #include ...

  3. 1030 大数进制转换(51Nod + JAVA)

    题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1030 题目: 代码实现如下: import java.mat ...

  4. poj1220(短除法实现任意进制转换)

    题目链接:https://vjudge.net/problem/POJ-1220 题意:给定a进制的大数s,将其转换为b进制.其中2<=a,b<=62. 题意:一般进制转换是以10进制为中 ...

  5. poj1220:高精度进制转换模板题

    今天撸3708  一直奇怪的re 就先放下了,写这个题的过程中学习了一个高精度进制转换,用这个模板写了1220 记录一下: #include <iostream> #include < ...

  6. poj1220 (高精度任意进制转换)

    http://poj.org/problem?id=1220 高精度任意进制转换 代码是从discuss里找到的,据说是maigo神牛写的. 超精简!! 我自己第一写的时候,还把n进制先转成10进制, ...

  7. 高精度进制转换(poj1220)

    常规短除法原理 高精度进制转换是对于特别大的数字来说的,当数字特别大时,难以进行除法和取余的操作,此时通过字符串模拟的办法可以解决. #include <iostream> #includ ...

  8. poj2305-Basic remains(进制转换 + 大整数取模)

    进制转换 + 大整数取模一,题意: 在b进制下,求p%m,再装换成b进制输出. 其中p为b进制大数1000位以内,m为b进制数9位以内二,思路: 1,以字符串的形式输入p,m; 2,转换:字符串-&g ...

  9. java se系列(二) 关键字、注释、常量、进制转换、变量、数据类型转换、运算符

    1 关键字 1.1 关键字的概述 Java的关键字对java的编译器有特殊的意义,他们用来表示一种数据类型,或者表示程序的结构等,关键字不能用作变量名.方法名.类名.包名. 1.2 常见的关键字 备注 ...

随机推荐

  1. 使apache的日志文件里不记录图片文件

    找到: LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-A ...

  2. CSDN日报20170413 ——《天天写业务代码的那些年,我们是怎样成长过来的》

    [程序人生]天天写业务代码的那些年,我们是怎样成长过来的 作者:Phodal 比起写业务代码更不幸的是,主要工作是修 Bug , bug , buG , bUg. [Java 编程]Springboo ...

  3. 配置Linux系统实现dhcp功能

    配置Linux系统实现dhcp功能 1.背景及原理    DHCP(Dynamic Host Configuration Protocol,动态主机配置协议)通常被应用在大型的局域网络环境中,主要作用 ...

  4. Location配置与ReWrite语法

    1 Location语法规则 1.1 Location规则 语法规则: location [=|~|~*|^~] /uri/ {… } 首先匹配 =,其次匹配^~,其次是按文件中顺序的正则匹配,最后是 ...

  5. Unity3D的三种坐标系

    来自:http://blog.csdn.net/luxiaoyu_sdc/article/details/13168497 1, World Space(世界坐标): 我们在场景中添加物体(如:Cub ...

  6. inspect模块详解

    inspect模块主要提供了四种用处: (1).对是否是模块,框架,函数等进行类型检查. (2).获取源码 (3).获取类或函数的参数的信息 (4).解析堆栈 使用inspect模块可以提供自省功能, ...

  7. SRM 515 DIV1 550pt

    题目大意: n个人进入商店买东西,对于每个顾客都有T.C.P这3个数组,表示有Pj的概率第i个顾客在Tj的时间进入商店以Cj的价格买东西,每个顾客Pj的和小于等于1,保证每个时间只最多只有一个顾客可能 ...

  8. c语言字符串赋值

    char *p="asdf";能运行 定义一个字符指针,并用它指向常量字符串"asdf"的首地址 char *p;p="asdf"; 能运行 ...

  9. java 乱码问题解决思路

    "编码一致的条件下,在处理运行正常的情况下,是不会出现乱码的",记住这句金言. 如上所说,如果编码一致是不会出现这种乱码问题,所以解决办法就是仔细再仔细的检查所设置的编码是否是一致 ...

  10. statusbar的颜色设置

    步骤一.在info.plist文件中添加一行(key:View controller-based status bar appearance,value:NO) 步骤二.在appDelegate中,添 ...