HDU 1335 Basically Speaking(进制转换)
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.
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.
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.
#include<stdio.h>
#include<cstring>.
#include<iostream>
using namespace std;
char s[];
int a,b;
int len,i,j;
long long c;
char ans[];
int f(int j)
{
int res=;
while(j--)
res*=a;
return res;
}
int main()
{
while(cin>>s>>a>>b)
{
len=strlen(s);
c=;
for(i=len-,j=;i>=;i--,j++)
{
if(s[i]>=''&&s[i]<='')
c+=(s[i]-'')*f(j);
else
c+=(s[i]-'A'+)*f(j);
}
//从a进制转化为十进制c
//cout<<c<<" ";//
//接下来从十进制c转换为b进制字符串ans
for(i=;i<;i++)
{
if(c<)break;
ans[i]=''+(c%b);
c/=b;
}
int len1=i;
//cout<<len1<<" ";//
if(len1>)cout<<" ERROR"<<endl;
else
{
for(i=;i<=-len1;i++)cout<<" ";
for(i=len1-;i>=;i--)
{
if(ans[i]>=''&&ans[i]<='')
cout<<ans[i];
else
printf("%c",ans[i]-''-+'A');
}
cout<<endl;
}
}
return ;
}
HDU 1335 Basically Speaking(进制转换)的更多相关文章
- HDOJ 1335 Basically Speaking(进制转换)
Problem Description The Really Neato Calculator Company, Inc. has recently hired your team to help d ...
- HDU 2097 Sky数 进制转换
解题报告:这题就用一个进制转换的函数就可以了,不需要转换成相应的进制数,只要求出相应进制的数的各位的和就可以了. #include<cstdio> #include<string&g ...
- HDU 5050 Divided Land(进制转换)
题意 给你两个二进制数m,n 求他们的最大公约数 用二进制表示 0<m,n<2^1000 先把二进制转换为十进制 求出最大公约数 再把结果转换为二进制 数比較大要用到大数 ...
- HDU 2031 进制转换(10进制转R进制)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2031 进制转换 Time Limit: 2000/1000 MS (Java/Others) M ...
- hdu 2031 进制转换(栈思想的使用)
进制转换 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDU 1877 又一版 A+B(进制转换)
看了http://lovnet.iteye.com/blog/1690276的答案 好巧妙的方法 递归实现十进制向m进制转换 #include "stdio.h" int m; v ...
- CF 552C 进制转换
http://codeforces.com/problemset/problem/552/C C. Vanya and Scales time limit per test 1 second memo ...
- 进制转换,杭电0j-2031
进制转换,杭电0j-2031原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=2031 [Problem Description] 输入一个十进制数N,将它 ...
- SQL Server 进制转换函数
一.背景 前段时间群里的朋友问了一个问题:“在查询时增加一个递增序列,如:0x00000001,即每一个都是36进位(0—9,A--Z),0x0000000Z后面将是0x00000010,生成一个像下 ...
随机推荐
- elasticsearch查询模板
{ "from":#from#, "size":#size#, "_source":#source#, "query": ...
- GourdScan & sqlmapapi
0x01 Windows下配置GourdScan 0x0101 GourdScan项目地址:https://github.com/code-scan/GourdScan PHP环境 + ...
- 遇到个奇怪的问题,同时开启本地和远程两个事务,远程事务是sql2000没问题,是sql2008的不报错,但是写不上数据
遇到个奇怪的问题,同时开启本地和远程两个事务,远程事务是sql2000没问题,是sql2008的不报错,但是写不上数据. 倒腾了4.5天,找到最终的解决办法:直接调用AdoConnection.exe ...
- 手工场景--controller--场景设计、场景监控、运行场景
场景设置: 1.设置界面 2.全局设置. A:初始化: B:启动用户: C:
- php学习笔记——日期和时间
一.time() 来取得服务器当前时间的时间戳 UNIX 时间戳(timestamp)是 PHP 中关于时间日期一个很重要的概念,它表示从 1970年1月1日 00:00:00 到当前时间的秒数之和. ...
- NTSC色域(CIE1931)计算公式
色域(CIE1931)=ABS(RC[-6]*RC[-3]+RC[-4]*RC[-1]+RC[-2]*RC[-5]-RC[-6]*RC[-1]-RC[-4]*RC[-5]-RC[-2]*RC[-3]) ...
- 给Unity3d添加一个漂亮的标题栏
我们在做好一个小Unity3d APP,我们一般都会兴致勃勃的导出一个exe,尝试着玩我们的app.感觉还不错,有板有眼的了.然而事与愿违,我们APP里面的内容挺漂亮的,但是它的标题栏是windows ...
- bitcode 关于讯飞
在真机调试的时候一直报 ld: '/Users/Chenglijuan/Documents/语音识别/lib/iflyMSC.framework/iflyMSC(IFlyRecognizerView. ...
- 创建 userSettings/Microsoft.SqlServer.Configuration.LandingPage.Properties.Settings 的配置节处理程序时出错: 未能加载文件或程序集“System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”或它的某一个依赖项。系统没找到指定的文件
创建 userSettings/Microsoft.SqlServer.Configuration.LandingPage.Properties.Settings 的配置节处理程序时出错: 未能加载文 ...
- mob.com Android studio 配置环境