(高精度运算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_1 { public static void main(String[] args) {
Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); while(t > 0){
BigInteger ba1 = scanner.nextBigInteger();
BigInteger ba2 = scanner.nextBigInteger();
BigInteger sum = new BigInteger("0"); String str = scanner.next(); int len = str.length();
int i;
int count = 0;
int temp;
for(i = len - 1; i >= 0 ; --i){//先将输入的ba1进制的数按照给定的规则转化成10进制的数
char w = str.charAt(i);
temp = 0;
if(Character.isDigit(w)){
temp = w - '0';
}else if(Character.isLowerCase(w)){
temp = w - 'a' + 36;
}else if(Character.isUpperCase(w)){
temp = w - 'A' + 10;
} sum = sum.add(new BigInteger(temp + "").multiply(ba1.pow(count++))); } BigInteger zero = new BigInteger("0");
int top = 0;
int stack[] = new int[2000];
while(sum.compareTo(zero) != 0){//转化成指定ba2进制的数
stack[++top] = sum.mod(ba2).intValue();
sum = sum.divide(ba2);
} System.out.println(ba1+" "+str);
System.out.print(ba2+" ");
if(top == 0){
System.out.print(0);
} while(top != 0){
char w = 0;
temp = stack[top--];
if(temp < 10){
w = (char) (temp +'0');
}else if(temp>= 10 && temp < 36){
w = (char) (temp +'A' - 10);
}else if(temp >= 36){
w = (char) (temp + 'a' - 36);
} System.out.print(w);
} System.out.println();
System.out.println();
t--;
} }
}
(高精度运算4.7.26)POJ 1220 NUMBER BASE CONVERSION(高精度数的任意进制的转换——方法:ba1----->10进制----->ba2)的更多相关文章
- poj 1220 NUMBER BASE CONVERSION(短除法进制转换)
题目连接:1220 NUMBER BASE CONVERSION 题目大意:给出两个进制oldBase 和newBase, 以及以oldBase进制存在的数.要求将这个oldBase进制的数转换成ne ...
- 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还是原来的 ...
- NUMBER BASE CONVERSION(进制转换)
Description Write a program to convert numbers in one base to numbers in a second base. There are 62 ...
- SZU:J38 Number Base Conversion
Judge Info Memory Limit: 32768KB Case Time Limit: 1000MS Time Limit: 1000MS Judger: Number Only Judg ...
- POJ1220 Number Base Conversion
题意 Write a program to convert numbers in one base to numbers in a second base. There are 62 differen ...
- [POJ1220]NUMBER BASE CONVERSION (高精,进制转换)
题意 任意进制之间的高进的转换 思路 相模倒排,高精处理 代码 我太弱了,下面附一个讨论里发的maigo思路的代码 ],A[]; ],d[]; main(){ for(scanf("%d&q ...
- [code]高精度运算
数组存储整数,模拟手算进行四则运算 阶乘精确值 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 #includ ...
- poj 1220(短除法)
http://poj.org/problem?id=1220 题意:进制转换,把a进制转换为b进制. 如果数据不大的话,那么这个题还是很简单的,但这个题就是数据范围太大,所以这里可以采用短除法来做. ...
随机推荐
- win下 golang 跨平台编译
mac 下编译其他平台的执行文件方式请参看这篇文章,http://www.cnblogs.com/ghj1976/archive/2013/04/19/3030703.html 本篇文章是win下的 ...
- robotframework学习
下载地址: https://pypi.python.org/pypi/robotframework Installation If you already have Python with pip i ...
- 淘宝API开发(三)
自动登录到淘宝定时获取订单: C#控制台程序 第一步,获得淘宝真实登录地址.淘宝授权地址(https://oauth.taobao.com/authorize?response_type=token& ...
- Ruby相关图书推荐
Ruby基础教程第4版 作 者 [日] 高桥征义,[日] 后藤裕藏 著:何文斯 译:[日] 松本行弘 校 出 版 社 人民邮电出版社 出版时间 2014-09-01 版 次 4 页 ...
- 移动开发必备!15款jQuery Mobile插件
移动互联网的发展,来自PC端的网页并不能完全自适应移动端页面需求,使得响应式设计体验产生并成为潮流,也正是这样一种需求,促成了jQuery Mobile的流行.jQuery Mobile这样一款基于j ...
- APT攻击将向云计算平台聚焦
APT攻击作为一种高效.精确的网络攻击方式,在近几年被频繁用于各种网络攻击事件之中,并迅速成为企业信息安全最大的威胁之一. 近日,飞塔中国首席技术顾问X在谈及APT攻击时表示,随着云计算的不断发展普及 ...
- 解决SQL Server Always 日志增大的问题-摘自网络
配置了Alwayson之后,因为没有只能使用完全恢复模式,不能使用简单或大容量日志模式,所以日志不断增长,不能使用改变恢复模式的方式清空日志 手动操作收缩或截断日志也无效 读了一些文章后发现,有人使用 ...
- Apache Spark shell的实例操作
1.scala> val inFile = sc.textFile("./spam.data") 作用是将spam.data当作文本文件加载到Spark中,将spam.dat ...
- 解析XtraBackup备份MySQL的原理和过程(转)
原文:http://ourlinux.blog.51cto.com/274624/844859 XtraBackup是percona公司提供的开源工具,以热备Innodb表著称而被广泛采用. Xtra ...
- AutoCAD.NET 不使用P/Invoke方式调用acad.exe或accore.dll中的接口(如acedCommand、acedPostCommand等)
使用C#进行AutoCAD二次开发,有时候由于C#接口不够完善,或者低版本AutoCAD中的接口缺少,有些工作不能直接通过C#接口来实现,所以需要通过P/Invoke的方式调用AutoCAD的其他DL ...