首页 技术 正文
技术 2022年11月7日
0 收藏 547 点赞 604 浏览 1144 个字
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--;
}}
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,083
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,558
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,407
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,180
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,816
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,899