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. Chapter 15_3 使用环境

    创建模块的基本方法的缺点在于,忘记使用local,很容易就污染全局空间. “函数环境”是一种有趣的技术,它能够解决上面的问题.就是让模块的主程序块独占一个环境. 这样不仅它的所有函数可以共享这个tab ...

  2. urllib2 之info 学习

    之前介绍了根据old_url获取真实url的geturl的方法,而根据urlopen返回的应答对象的info方法可以获取服务器发送头部headers的内容,并且通过字典形式反馈出来,同样测试代码如下: ...

  3. rabbitmq——镜像队列

    转自:http://my.oschina.net/hncscwc/blog/186350?p=1 1. 镜像队列的设置 镜像队列的配置通过添加policy完成,policy添加的命令为: rabbit ...

  4. sqlserver 经典入门基础书籍

    1.SQLServer2005T-SQL数据库设计 作者:胡百敬等著 ISBN:10位[7121053632]13位[9787121053634] 出版社:电子工业出版社 出版日期:2008-1-1 ...

  5. css sprite的使用心得

    提高网页显示速度最有效的一个方法是减少页面的HTTP请求次数,为了减少HTTP请求次数,最直接有效的方法是使用精灵图片(CSS sprites),精灵图片是把许多图片放到一张大图片里面,通过CSS来显 ...

  6. Java自学之路---DotCom

    引言 我从接触编程以来,一直是一个C/C++程序猿,因为我喜欢编程时,那种接地气的感觉,认为只有自己管理内存的使用,心理才踏实.但随着工作中不断增加的见闻,不断的从博客和源码中获得新的见解,我发现这个 ...

  7. shape的使用

    android在布局边缘位置处理圆角的两个办法: 1),一个是直接让美工切一张带有圆角的图片. 2),使用shape来解决. 第一种不在赘述,主要讲一下第二中方法来实现. 上边缘出现圆角,下边缘正常的 ...

  8. petstore-jdbc

    拖了好多天,终于决定开始写作业了,搞了大半天的把软件安好. jdk(安装与环境配置) Tomcat(安装与环境配置) mysql(安装,同时配置图形化操作界面) eclipse for Javaee ...

  9. R语言笔记3--实例1

    综合性例子: 模拟产生统计专业同学的名单(学号区分),记录数学分析,线性代数.概率统计三科成绩,然后进行一些统计分析 1.首先产生一个向量(100个元素,代表100位学生) 2.模拟成绩 runif: ...

  10. swap in java?

    Is it possible to write a swap method in java? these two variables will be primitives. It's not poss ...