Basically Speaking

Time Limit: 2 Sec  Memory Limit: 200 MB

Submit: 19  Solved: 11

[Submit][Status][Web Board]

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

#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int a,b,l,i;
long long sum;
char ch[];
int work(char ch)
{
if(ch>='' && ch<='') return ch-'';
return ch-'A'+;
}
char solve(int k)
{
if (k<) return char(k+);
return char(k+);
}
int main()
{
while(~scanf("%s%d%d",&ch,&a,&b))
{
l=strlen(ch);
sum=;
for(int i=;i<l;i++)
sum=sum*a+work(ch[i]);
if (sum==)
{
printf(" 0\n");
continue;
}
l=;
while(sum>)
{
ch[++l]=solve(sum%b);
sum=sum/b;
}
if (l<=)
{
for(i=;i<=-l;i++) printf(" ");
for(i=l;i>=;i--) printf("%c",ch[i]);
}
else printf(" ERROR");
printf("\n");
}
return ;
}

Basically Speaking的更多相关文章

  1. HDU-1335 Basically Speaking

    http://acm.hdu.edu.cn/showproblem.php?pid=1335 Basically Speaking Time Limit: 2000/1000 MS (Java/Oth ...

  2. ZOJ Problem Set - 1334 Basically Speaking ac代码及总结

    这道题目不难,是一道简单的进制转换问题,但是发现了自己两个遗漏的知识点: 1.关于scanf (1)scanf函数在输入时是以回车或者空格作为一次输入的结束 (2)scanf函数在输入字符串的过程中是 ...

  3. HDOJ 1335 Basically Speaking(进制转换)

    Problem Description The Really Neato Calculator Company, Inc. has recently hired your team to help d ...

  4. HDU 1335 Basically Speaking(进制转换)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1335 Problem Description The Really Neato Calculator ...

  5. ZOJ Problem Set - 1394 Polar Explorer

    这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...

  6. POJ 题目分类(转载)

    Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...

  7. HDU——PKU题目分类

    HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...

  8. (转)POJ题目分类

    初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推. ...

  9. poj分类

    初期: 一.基本算法:      (1)枚举. (poj1753,poj2965)      (2)贪心(poj1328,poj2109,poj2586)      (3)递归和分治法.      ( ...

随机推荐

  1. C# 语言规范_版本5.0 (第3章 基本概念)

    1. 基本概念 1.1 应用程序启动 具有入口点 (entry point) 的程序集称为应用程序 (application).应用程序运行时,将创建新的应用程序域 (application doma ...

  2. poj 2299 Ultra-QuickSort 逆序对模版题

    用树状数组求逆序数 唯一的坑点就是sum要用long long存 直接贴代码了 以后忘了还能直接看 2333…… PS:和hdu3743代码是一样的,因为两个都是逆序对模版题…… #include&l ...

  3. tomcat容器启动的启动过程(三)

    Catalina的start方法 /** * Start a new server instance. */ public void start() { if (server == null) { l ...

  4. Sublime Text学习笔记

    1.快捷键(Key Bindings)   Preferences -> Key Bindings ->Default   会打开一个配置文件,里面全是配置信息 2.代码片段(Snippe ...

  5. 移动端日历控件 mobiscroll 的简单使用、参数设置

    mobiscroll 在性能方面比较好,可选用多种效果,滑动效果也比较顺畅.   提供样式文件和js文件,直接点击下载,该版本是 mobiscroll 2.13的 官方地址 :https://docs ...

  6. buffer小解

    Buffer代表一个缓冲区,存储二进制数据,是字节流 创建: 创建Buffer有4种方式: 1.new Buffer(size) 以字节为单位创建指定大小的Buffer eg: var buf= ne ...

  7. Centos6.6升级python版本

    centos原生python为2.6.6,可以通过下面的命令查看 #python -V Python 注:在安装新版本前,请先安装zlib\openssl组件,如果你确认你用不到这个,也可以不装 需要 ...

  8. 使用非 GUI 模式运行 JMeter 压力测试

    使用非 GUI 模式,即命令行模式运行 JMeter 测试脚本能够大大缩减所需要的系统资源.使用命令jmeter -n -t <testplan filename> -l <list ...

  9. 《C++ Primer》之重载操作符与转换(中)

    赋值操作符 类赋值操作符接受类类型形参,通常,该形参是对类类型的 const 引用,但也可以是类类型或对类类型的非 const 引用.如果没有定义这个操作符,则编译器将合成它.类赋值操作符必须是类的成 ...

  10. TCP/IP协议学习之实例ping命令学习笔记

    TCP/IP协议学习之实例ping命令学习笔记(一) 一. 目的为了让网络协议学习更有效果,在真实网络上进行ping命令前相关知识的学习,暂时不管DNS,在内网中,进行2台主机间的ping命令的整个详 ...