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)递归和分治法. ( ...
随机推荐
- poj 1411 Calling Extraterrestrial Intelligence Again
题意:给你数m,a,b,假设有数p,q,满足p*q<=m同时a/b<=p/q<=1,求当p*q最大的p和q的值 方法:暴力枚举 -_-|| and 优化范围 我们可以注意到在某一个m ...
- hdu 计算机学院大学生程序设计竞赛(2015’11)
搬砖 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submissi ...
- redis3--key的操作
我们之前使用Redis简单存储了三个参数:在语句set name jack中,其中name就是一个key.我们Java中的变量名是有一定规则的,比如组成内容可以是"数字",&quo ...
- oracle日期的处理
字符长转换为日期,有两种写法 SELECT date'2016-06-03' FROM dualselect to_date('2016-06-03','yyyy-mm-dd') from dual ...
- ZOJ 649 Rescue(优先队列+bfs)
Rescue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...
- Oracle教程-常用命令(二)
oracle sql*plus常用命令 一.sys用户和system用户Oracle安装会自动的生成sys用户和system用户(1).sys用户是超级用户,具有最高权限,具有sysdba角色,有cr ...
- Redhat_AS5下安装MySQL5.0总结
一.引言 使用Linux也有几年时间了,由于公司要做radius服务器用用到MySQL.从网上找了些资料. 二.安装Mysql 1.下载MySQL的安装文件 安装MySQL需要下面两个文件: MySQ ...
- string的数值转换
to_string(val); //数值val的string表示 stoi (s, p, b); stol (s, p, b); stoul (s, p, b); stoll (s, p, b); s ...
- 美版MC 使用
备份 C:\ProgramData\TS Support\MultiCharts .NET\StudyServer\Techniques\CS pledit 无法打开 解决方法 regedit hke ...
- Git合并分支出现的冲突解决
人生不如意之事十有八九,合并分支往往也不是一帆风顺的. 我们准备新的分支newbranch. LV@LV-PC MINGW32 /c/gitskill (master)$ git checkout - ...