博客
关于我
P1604_B进制星球(JAVA语言)
阅读量:132 次
发布时间:2019-02-27

本文共 941 字,大约阅读时间需要 3 分钟。

思路:BigInteger 五杀!利用BigInteger自带的进制转换。

//第一次提交WA了几组数据,下载测试数据发现带字母的答案要转换为大写。

题目背景

进制题目,而且还是个计算器~~

题目描述

话说有一天,小Z乘坐宇宙飞船,飞到一个美丽的星球。因为历史的原因,科技在这个美丽的星球上并不很发达,星球上人们普遍采用B(2<=B<=36)进制计数。星球上的人们用美味的食物招待了小Z,作为回报,小Z希望送一个能够完成B进制加法的计算器给他们。 现在小Z希望你可以帮助他,编写实现B进制加法的程序。

输入输出格式

输入格式:

 

共3行第1行:一个十进制的整数,表示进制B。第2-3行:每行一个B进制数正整数。数字的每一位属于{0,1,2,3,4,5,6,7,8,9,A,B……},每个数字长度<=2000位。

 

输出格式:

 

一个B进制数,表示输入的两个数的和。

 

输入输出样例

输入样例#1: 复制

4123321

输出样例#1: 复制

1110

说明

进制计算器

import java.math.BigInteger;import java.util.Scanner;public class Main {	public static void main(String[] args) {		// TODO Auto-generated method stub		Scanner in=new Scanner(System.in);		int n=in.nextInt();		String a=in.next();//读入		String b=in.next();		BigInteger cona= new BigInteger(a,n);//将一个n进制的a转换为10进制		BigInteger conb= new BigInteger(b,n);//将一个n进制的b转换为10进制		BigInteger c=cona.add(conb);//计算两个十进制数和		String s=new BigInteger(c+"",10).toString(n);//将一个10进制的c转换为n进制		System.out.println(s.toUpperCase());	}}

 

转载地址:http://rzcb.baihongyu.com/

你可能感兴趣的文章
nginx+php的搭建
查看>>
nginx+tomcat+memcached
查看>>
nginx+tomcat单个域名及多个域名配置
查看>>
Nginx+Tomcat实现动静分离
查看>>
nginx+Tomcat性能监控
查看>>
nginx+uwsgi+django
查看>>
nginx+vsftp搭建图片服务器
查看>>
Nginx-http-flv-module流媒体服务器搭建+模拟推流+flv.js在前端html和Vue中播放HTTP-FLV视频流
查看>>
nginx-vts + prometheus 监控nginx
查看>>
Nginx/Apache反向代理
查看>>
Nginx: 413 – Request Entity Too Large Error and Solution
查看>>
nginx: [emerg] getpwnam(“www”) failed 错误处理方法
查看>>
nginx: [emerg] the “ssl“ parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:
查看>>
nginx: [error] open() “/usr/local/nginx/logs/nginx.pid“ failed (2: No such file or directory)
查看>>
nginx:Error ./configure: error: the HTTP rewrite module requires the PCRE library
查看>>
Nginx:objs/Makefile:432: recipe for target ‘objs/src/core/ngx_murmurhash.o‘解决方法
查看>>
nginxWebUI runCmd RCE漏洞复现
查看>>
nginx_rtmp
查看>>
Vue中向js中传递参数并在js中定义对象并转换参数
查看>>
Nginx、HAProxy、LVS
查看>>