ZOJ 1352 Number Base Conversion
来源:互联网 发布:js实现点击收缩和展开 编辑:程序博客网 时间:2024/05/16 15:57
才发现用java编写大数运算问题,真的是好简单啊!下面的代码是copy别人的,以后要注意java的编写了。。。
第一次用java 提交,提交时要注意:必须使用public class Main。。。
import java.util.Scanner;
import java.math.BigInteger;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int cnt = input.nextInt();
while(cnt-- != 0) {
int a = input.nextInt();
int b = input.nextInt();
String x = input.next();
String y = "";
BigInteger A = new BigInteger(Integer.toString(a));
BigInteger B = new BigInteger(Integer.toString(b));
BigInteger n = new BigInteger("0");
for(int i = 0; i < x.length(); i++) {
if(x.charAt(i) >= '0' && x.charAt(i) <= '9')
n = n.add(new BigInteger(Integer.toString(x.charAt(i) - '0')));
else if (x.charAt(i) >= 'A' && x.charAt(i) <= 'Z')
n = n.add(new BigInteger(Integer.toString(x.charAt(i) - 'A' + 10)));
else
n = n.add(new BigInteger(Integer.toString(x.charAt(i) - 'a' + 36)));
if(i != x.length() - 1) n = n.multiply(A);
}
if(n.signum() == 0) y = "0";
while(n.signum() != 0) {
int t = n.mod(B).intValue();
if(t < 10)
y = t + y;
else if(t >= 10 && t < 36)
y = (char)(t - 10 + 'A') + y;
else
y = (char)(t - 36 + 'a') + y;
n = n.divide(B);
}
System.out.println(a + " " + x);
System.out.println(b + " " + y);
System.out.println();
}
}
}
- ZOJ 1352 Number Base Conversion
- poj1220 NUMBER BASE CONVERSION
- POJ 1220 NUMBER BASE CONVERSION
- POJ 1220 Number Base Conversion
- POJ 1220 NUMBER BASE CONVERSION
- SZU:J38 Number Base Conversion
- NUMBER BASE CONVERSION(高精度)
- poj 1220 NUMBER BASE CONVERSION
- POJ 1220 NUMBER BASE CONVERSION
- NUMBER BASE CONVERSION(进制转化)
- poj 1220 NUMBER BASE CONVERSION 【栈】
- 进制转换 poj1220-NUMBER BASE CONVERSION
- POJ 1220 NUMBER BASE CONVERSION JAVA .
- POJ 1220 NUMBER BASE CONVERSION 笔记
- pku 1220--NUMBER BASE CONVERSION(高精度进制转换)
- POJ 1220 NUMBER BASE CONVERSION(高精度--进制转换)
- poj 1220 NUMBER BASE CONVERSION(字符串处理经典)
- poj 1220 NUMBER BASE CONVERSION 高精度进制转换
- 扩展Outlook 用户显示信息!
- Unix环境高级编程学习笔记(十二) 高级进程间通信
- 设计模式—工厂模式
- POJ 1190 生日蛋糕 估计最小答案dfs剪枝
- Latex输出行列式、矩阵、方程组
- ZOJ 1352 Number Base Conversion
- 【朴素贝叶斯】实战朴素贝叶斯_代码实现_预测
- UVaOJ 494 - Kindergarten Counting Game
- TC 555 div2
- [Hadoop源码解读](六)MapReduce篇之MapTask类
- Android中巧妙的位运算
- Lucene小练二(还是索引)
- 已解决:函数重载 原因:临时变量不能作为非const的引用参数传递
- 有关SD卡接线的探索(为什么标准SD卡是九根线,而一般原理图上都是11根线或更多呢?)