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. 关于jquery选择器中:first和:first-child和:first-of-type的区别及:nth-child()和:nth-of-type()的区别

    :first:选择第一个出现符合的元素 :first-child:选择限制条件中的第一个元素,并且必须和冒号前面的标签一致 :first-of-type:选择所有限制条件下的第一个冒号前面的标签元素, ...

  2. 洛谷-ISBN号码-简单字符串

    题目描述 Description 每一本正式出版的图书都有一个ISBN号码与之对应,ISBN码包括9位数字.1位识别码和3位分隔符,其规定格式如“x-xxx-xxxxx-x”,其中符号“-”就是分隔符 ...

  3. 如何利用 MembershipUser 更改密码

    如何利用 MembershipUser 更改密码 作者: vkvi 来源:千一网络 (原创) 时间: 2009-3-11   完美集成.增强 KindEditor HTML 编辑器 在 ASP.NET ...

  4. 安装jar包到本地maven仓库

    1.打开cmd 直接输入一下命令 自己下载的jar包放在d盘根目录下,jar名字叫spring-context-support-3.1.0.RELEASE.jar DgroupId后面写的是group ...

  5. python爬虫学习--防盗链

    一 首先要了解什么是盗链 盗链是指服务提供商自己不提供服务的内容,通过技术手段绕过其它有利益的最终用户界面(如广告),直接在自己的网站上向最终用户提供其它服务商的服务内容,骗取最终用户的浏览和点击率. ...

  6. Android jni编辑.so库

    引自:http://www.cnblogs.com/sevenyuan/p/4202759.html 1. 在Eclipse中创建项目:TestJNI 2. 新创建一个class:TestJNI.ja ...

  7. Java自学之路---DotCom

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

  8. vb asp.net的一些属性值

    AutoGenerateColumns 就是自动产生列的意思gridview等控件,如果设置了AutoGenerateColumns=true,就能够根据数据源的实际情况,自动生成gridview表格 ...

  9. LeetCode OJ 141. Linked List Cycle

    Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it without using ext ...

  10. Go-new和make

    new返回指向struct的指针,new仅分配内存,而不对对象的值进行初始化 make返回到strcut的对象,而不是指针,只能创建map,slice,channel对象 make([]string, ...