Problem Description

The Really Neato Calculator Company, Inc. has recently hired your team to help design their Super Neato Model I calculator. As a computer scientist you suggested to the company that it would be neato if this new calculator could convert among number bases. The company thought this was a stupendous idea and has asked your team to come up with the prototype program for doing base conversion. The project manager of the Super Neato Model I calculator has informed you that the calculator will have the following neato features:

It will have a 7-digit display.

Its buttons will include the capital letters A through F in addition to the digits 0 through 9.

It will support bases 2 through 16.

Input

The input for your prototype program will consist of one base conversion per line. There will be three numbers per line. The first number will be the number in the base you are converting from. The second number is the base you are converting from. The third number is the base you are converting to. There will be one or more blanks surrounding (on either side of) the numbers. There are several lines of input and your program should continue to read until the end of file is reached.

Output

The output will only be the converted number as it would appear on the display of the calculator. The number should be right justified in the 7-digit display. If the number is to large to appear on the display, then print “ERROR” (without the quotes) right justified in the display.

Sample Input

1111000  2 10
1111000 2 16
2102101 3 10
2102101 3 15
12312 4 2
1A 15 2
1234567 10 16
ABCD 16 15

Sample Output

    120
78
1765
7CA
ERROR
11001
12D687
D071

输入3个数:n a b

输入的n是a进制的数,需要把n再转换成b进制的数。

如果转换之后的数字位数超过了7,就输出“ ERROR”。

每个输出占7位,不足7位的左边补空格。

import java.util.Scanner;

public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String strNum = sc.next();
int a = sc.nextInt();
int b = sc.nextInt(); int s = Integer.valueOf(strNum, a);
//将a进制的strNum转换成10进制s
String sNum = Integer.toString(s, b); if(sNum.length()>7){
System.out.println(" ERROR");
continue;
} for(int i=7;i>sNum.length();i--){
System.out.print(" ");
}
System.out.println(sNum.toUpperCase()); } } }

HDOJ 1335 Basically Speaking(进制转换)的更多相关文章

  1. hdoj 2031 进制转换

    进制转换 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  2. 2031 HDOJ 进制转换

    Problem Description 输入一个十进制数N,将它转换成R进制数输出.   Input 输入数据包含多个测试实例,每个测试实例包含两个整数N(32位整数)和R(2<=R<=1 ...

  3. CF 552C 进制转换

    http://codeforces.com/problemset/problem/552/C C. Vanya and Scales time limit per test 1 second memo ...

  4. Java练习 SDUT-1253_进制转换

    进制转换 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 输入一个十进制数N,将它转换成R进制数输出. Input 输入 ...

  5. SQL Server 进制转换函数

    一.背景 前段时间群里的朋友问了一个问题:“在查询时增加一个递增序列,如:0x00000001,即每一个都是36进位(0—9,A--Z),0x0000000Z后面将是0x00000010,生成一个像下 ...

  6. [No000071]C# 进制转换(二进制、十六进制、十进制互转)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  7. JS中的进制转换以及作用

    js的进制转换, 分为2进制,8进制,10进制,16进制之间的相互转换, 我们直接利用 对象.toString()即可实现: //10进制转为16进制 ().toString() // =>&q ...

  8. 结合stack数据结构,实现不同进制转换的算法

    #!/usr/bin/env python # -*- coding: utf-8 -*- # learn <<Problem Solving with Algorithms and Da ...

  9. 进制转换( C++字符数组 )

    注: 较为简便的方法是用 整型(int)或浮点型(long.double 注意:该类型不一定能够准确存储数据) 来存放待转换的数值,可直接取余得到每一位数值 较为稳定的方法是用 字符数组储存待转换的数 ...

随机推荐

  1. linux crontab 定时命令

    一直认为Timer是比较好的实现定时器的方法,后来遇到在linux下的命令制定定时任务才发现,Timer的劣势所在,在Timer的时候很可能你的任务会被当做一个死程序被杀掉等等......上次一个同事 ...

  2. hdu5032 Always Cook Mushroom

    题意是这样,给定一个1000x1000的点阵.m组询问.每次询问一个由(0,0).(x,0)点一以及从原点出发的方向向量(a,b)构成的直角三角形包围的点的权值和. 点的权值是(x+A)(y+B),当 ...

  3. HTML编辑器UEditor的简单使用

    參考自:http://ueditor.baidu.com/website/document.html 关于HTML编辑器,试过FCKeditor,升级版的CKeditor,还有TinyMCE,近期在尝 ...

  4. txt文件导入mysql--转

    MySQL写入数据通常用insert语句,如 insert into person values(张三,20),(李四,21),(王五,70)…; 但有时为了更快速地插入大批量数据或交换数据,需要从文 ...

  5. MySQL(12):windows下解决mysql忘记密码

    mysql有时候忘记密码了怎么办?我给出案例和说明!一下就解决了!    Windows下的实际操作如下 : 1. 关闭正在运行的MySQL.  2. 打开DOS窗口,转到mysql\bin目录. 3 ...

  6. apache SetEnv 设置

    php的服务器预定义变量 $_SERVER 可以通过apache的mod_env模块来添加我们所需要的内容 来段官网介绍 Description: Modifies the environment w ...

  7. setTimeout()与setInterval()方法区别介绍

    计时器setTimeout()和setInterval()两个都是js的计时功能的函数两个有些区别,下面为大家简单介绍下,希望对大家有所帮助   计时器setTimeout()和setInterval ...

  8. 如何使用CSS Sprites技术进行图片合并

    http://jingyan.baidu.com/article/066074d6757654c3c21cb02d.html

  9. 如何分析apache日志[access_log(访问日志)和error_log(错误日志)]

    如何分析apache日志[access_log(访问日志)和error_log(错误日志)] 发布时间: 2013-12-17 浏览次数:205 分类: 服务器 默认Apache运行会access_l ...

  10. [linux常用命令]查看当前文件夹或该文件夹下文件(夹)的大小

    du -sh  *(星号表示当前所有文件夹)可以查看当前目录下各个文件夹的大小,-s表示只显示当前文件夹(不加-s你可以看到所有文件夹下的子文件夹的大小,太多了),-h表示以合适的大小查看.(可以用- ...