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--;
}
}
}
分享到:
相关推荐
02.北大POJ题库使用指南.docx02.北大POJ题库使用指南.docx02.北大POJ题库使用指南.docx02.北大POJ题库使用指南.docx02.北大POJ题库使用指南.docx02.北大POJ题库使用指南.docx02.北大POJ题库使用指南.docx02.北大POJ...
POj 1001源代码——高精度乘单精度POj 1001源代码——高精度乘单精度POj 1001源代码——高精度乘单精度POj 1001源代码——高精度乘单精度
包含15类的POJ推荐50题,可全面复习或学习算法。 除此外还包含三种级别的水平(初级、中级、高级)应掌握的算法及数据结构及... (poj3096,poj3007)(2)较为复杂的模拟题的训练(poj3393,poj1472,poj3371,poj1027,poj2706)
北大POJ1019-Number Sequence 解题报告+AC代码
poj 3593 Sea Base Exploration.md
poj 1663 Number Steps.md
(poj1860,poj3259,poj1062,poj2253,poj1125,poj2240) (3)最小生成树算法(prim,kruskal) (poj1789,poj2485,poj1258,poj3026) (4)拓扑排序 (poj1094) (5)二分图的最大匹配 (匈牙利算法) (poj3041,poj3020) ...
POJ 1006 源代码——中国剩余定理分析POJ 1006 源代码——中国剩余定理分析POJ 1006 源代码——中国剩余定理分析
北大POJ1004-Financial Management 解题报告+AC代码
cpp代码-2.25.2 poj 2258
POJ1048,加强版的约瑟夫问题 难度中等
POJ水题集-----50道左右-----增加自信啊..
北大POJ1014-Dividing【DFS】【多重背包+二进制优化】 解题报告+AC代码
POJ 2151 Check the difficulty of problems. Practice for dynamic planning.
在进行ACM编程训练时做字符串专题的一些题目(POJ1782,POJ1790,POJ1951,POJ2003,POJ2121)
北大POJ3414-Pots 解题报告+AC代码
poj 1028 Web Navigation 的代码,已通过!
只是poj上的一条题目,对于理解后缀数组很有帮助.poj3261