Basically Speaking
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的更多相关文章
- HDU-1335 Basically Speaking
http://acm.hdu.edu.cn/showproblem.php?pid=1335 Basically Speaking Time Limit: 2000/1000 MS (Java/Oth ...
- ZOJ Problem Set - 1334 Basically Speaking ac代码及总结
这道题目不难,是一道简单的进制转换问题,但是发现了自己两个遗漏的知识点: 1.关于scanf (1)scanf函数在输入时是以回车或者空格作为一次输入的结束 (2)scanf函数在输入字符串的过程中是 ...
- HDOJ 1335 Basically Speaking(进制转换)
Problem Description The Really Neato Calculator Company, Inc. has recently hired your team to help d ...
- HDU 1335 Basically Speaking(进制转换)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1335 Problem Description The Really Neato Calculator ...
- ZOJ Problem Set - 1394 Polar Explorer
这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...
- POJ 题目分类(转载)
Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...
- HDU——PKU题目分类
HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...
- (转)POJ题目分类
初期:一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. ...
- poj分类
初期: 一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. ( ...
随机推荐
- Objective-C中的instancetype与id的区别
一.什么是instancetype instancetype是clang 3.5开始,clang提供的一个关键字,表示某个方法返回的未知类型的Objective-C对象.我们都知道未知类型的的对象可以 ...
- maven入门(下)
Apache Maven 入门篇(下) 作者:George Ma 第一篇文章大概的介绍了一下Apache Maven以及它的下载和安装,并且运行了一个简单的示例.那么在对maven有了一点接触后,接下 ...
- sql参数化查询避免注入漏洞的原因探析
网上其他同学的都说是重用执行计划,将用户输入的作为文本查询,到底如何实现,我用下面三行代码来解析一下. DECLARE @test NVARCHAR() SET @test=' or 1='1 SEL ...
- 怎么取消ie浏览器body与html的间隙
在css文件第一行定义全局样式,可以消除html标签默认间隙*{margin:0;padding:0;}
- TCP网络编程小结
一.套接字编程基础 1.套接字地址结构 通用的地址结构是 struct sockaddr{ unsigned short sa_family; ]; } IPv4的套接字地址结构是 struct in ...
- 【转载】StringUtils方法介绍
org.apache.commons.lang.StringUtils中方法的操作对象是java.lang.String类型的对象,是JDK提供 的String类型操作方法的补充,并且是null安全的 ...
- 设计模式--静态工厂设计模式在android中的使用
今天看到这篇文章:http://www.androiddesignpatterns.com/2012/05/using-newinstance-to-instantiate.html public c ...
- centos7.2自带的php5.4升级为5.6
参考:http://jingyan.baidu.com/article/380abd0a1f176c1d91192c4b.html 今天在新购的阿里云上部署个phpmyadmin,结果显示了个如下信息 ...
- SCANF SCANF_S
今天在看C的教程的时候,用VS2013写了一小段代码 scanf("%f",&w); 提示需要在预编译器里添加 _CRT_SECURE_NO_WARNINGS, 百度了下 ...
- TCP/IP协议学习之实例ping命令学习笔记
TCP/IP协议学习之实例ping命令学习笔记(一) 一. 目的为了让网络协议学习更有效果,在真实网络上进行ping命令前相关知识的学习,暂时不管DNS,在内网中,进行2台主机间的ping命令的整个详 ...