题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1335
Problem 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<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(进制转换)的更多相关文章

  1. HDOJ 1335 Basically Speaking(进制转换)

    Problem Description The Really Neato Calculator Company, Inc. has recently hired your team to help d ...

  2. HDU 2097 Sky数 进制转换

    解题报告:这题就用一个进制转换的函数就可以了,不需要转换成相应的进制数,只要求出相应进制的数的各位的和就可以了. #include<cstdio> #include<string&g ...

  3. HDU 5050 Divided Land(进制转换)

    题意  给你两个二进制数m,n   求他们的最大公约数  用二进制表示  0<m,n<2^1000 先把二进制转换为十进制  求出最大公约数  再把结果转换为二进制  数比較大要用到大数 ...

  4. HDU 2031 进制转换(10进制转R进制)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2031 进制转换 Time Limit: 2000/1000 MS (Java/Others)    M ...

  5. hdu 2031 进制转换(栈思想的使用)

    进制转换 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  6. HDU 1877 又一版 A+B(进制转换)

    看了http://lovnet.iteye.com/blog/1690276的答案 好巧妙的方法 递归实现十进制向m进制转换 #include "stdio.h" int m; v ...

  7. CF 552C 进制转换

    http://codeforces.com/problemset/problem/552/C C. Vanya and Scales time limit per test 1 second memo ...

  8. 进制转换,杭电0j-2031

    进制转换,杭电0j-2031原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=2031 [Problem Description] 输入一个十进制数N,将它 ...

  9. SQL Server 进制转换函数

    一.背景 前段时间群里的朋友问了一个问题:“在查询时增加一个递增序列,如:0x00000001,即每一个都是36进位(0—9,A--Z),0x0000000Z后面将是0x00000010,生成一个像下 ...

随机推荐

  1. Josephus问题的不同实现方法与总结

    /************************************************************************/ /* Josephus问题--数组实现 */ /* ...

  2. 第一百二十六节,JavaScript,XPath操作xml节点

    第一百二十六节,JavaScript,XPath操作xml节点 学习要点: 1.IE中的XPath 2.W3C中的XPath 3.XPath跨浏览器兼容 XPath是一种节点查找手段,对比之前使用标准 ...

  3. keychain的使用

    通常情况下,我们用NSUserDefaults存储数据信息,但是对于一些私密信息,比如密码.证书等等,就需要使用更为安全的keychain了.keychain里保存的信息不会因App被删除而丢失,在用 ...

  4. c#:readonly与const的区别

    readonly与const的区别: 1.初始化:const  字段只能在该字段的声明中初始化. readonly  字段可以在声明或构造函数中初始化. 2.值: const 字段是编译时常量(con ...

  5. 文档在线预览开源实现方案一:OpenOffice + SwfTools + FlexPaper

    在文档在线预览方面,项目组之前使用的是Microsoft office web apps, 由于该方案需要按照微软License付费,项目经理要我预研一个文档在线预览的开源实现方案.仔细钻入该需求发现 ...

  6. CSS菜单横竖布局要点

    菜单纵向:把ul 元素的边框属性去除,li元素用border-top  上边框显示分离,把a 元素用display:block  text-decoration:none  去除默认下划线 菜单横向: ...

  7. Minicom配置及使用详解

    因为现在电脑基本不配备串行接口,所以,usb转串口成为硬件调试时的必然选择.目前知道的,PL2303的驱动是有的,在dev下的名称是ttyUSB*. minicom,tkterm都是linux下应用比 ...

  8. 又遇Release编译的一坑 -- 应用程序正常初始化(0xc000007b)失败。请单击“确定”,终止应用程序。

    项目中使用了xlslib库,以动态库形式编译,由于它没有生成链接库lib文件,所以官方提供的demo中有createDLL这个小程序用来生成lib文件.然而我又 no zuo no die了一次.   ...

  9. centos7 install rvm

    不管其他,先按要求更新一下包 yum install -y gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel li ...

  10. 5.MyBaits调用存储过程

    1.创建一个javaweb项目MyBatis_Part4_Procedure 2.在src下创建procedure.sql文件 --创建表 create table p_user( id number ...