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. [ An Ac a Day ^_^ ] UVALive 7270 Osu! Master

    2015icpc北京区域赛的签到题 还是很签到的 一次就过了 题意呢 就是统计B C后最长上升序列还有S的个数 当然B C要被S分割开…… /* *************************** ...

  2. css-文本垂直居中(转)

    css-文本垂直居中(转) 在说到这个问题的时候,也许有人会问CSS中不是有vertical-align属性来设置垂直居中的吗?即使是某些浏览器不支持我只需做少许的CSS Hack技术就可以啊!所以在 ...

  3. Openjudge-计算概论(A)-数组顺序逆放

    描述: 将一个数组中的值按逆序重新存放.例如,原来的顺序为8,6,5,4,1.要求改为1,4,5,6,8.输入输入为两行:第一行数组中元素的个数n(1<n<100),第二行是n个整数,每两 ...

  4. ural 1118. Nontrivial Numbers

    1118. Nontrivial Numbers Time limit: 2.0 secondMemory limit: 64 MB Specialists of SKB Kontur have de ...

  5. jq的siblings对a标签不起效

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. Python笔记2-20151023

    一.循环 Python的循环有两种,一种是for...in循环,依次吧list或tuple中的每个元素迭代出来. >>>names = ['Michael','Bob','Tracy ...

  7. sql语句的使用;

    1.导出数据库的语句: mysqldump -u root -p shop > d:\shop.sql

  8. C++设计模式-Iterator迭代器模式

    ref: http://www.cnblogs.com/onlycxue/archive/2013/12/25/3490738.html

  9. hdu 计算机学院大学生程序设计竞赛(2015’11)

    搬砖 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submissi ...

  10. 获取集合、数组后要判断为空的必要性以及根据构造器创建对象后不是null的证实

    在开发过程中,凡是获取到一个集合对象,在利用或者说遍历这个集合对象之前,都要进行是否为null以及size()>0的判断,但是如果size()>0的话,不是就已经可以说明此集合对象不为nu ...