题目链接: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. 【.NET-EF】Entity Framework学习笔记2 - 增删改(没查询)

    学习描述:用EF就像是省略了做实体类和DAL类,感觉是很方便,废话不多说,直接写步骤: 1.创建EF的edmx文件 这个其实在笔记1已说过,不过有些细节也要说,所以再说一遍,这里使用的是EF 6.1版 ...

  2. DB2表是否存在

    select count(1) from syscat.tables where tabname='T1';

  3. json格式化和查看工具

    以前一直以来都觉得xml个可读性要比json的可读性好,后来使用了JSON Viewer这个小工具之后,发现自己错了.之前认为json的可读性差,完全是因为没有很好的查看工具.JSON Viewer这 ...

  4. ps 如何裁切图片成一定的长宽高比例

    1打开一张图片然后点击拆件工具然后在面板上长宽高,按enter键盘,OK拆建完成

  5. 【转】Oracle + PHP Cookbook(php oracle clob 长度超过4000如何写入)

      在甲骨文LOB和PHP工作 由哈里Fuecks 达到4,000字节的限制?输入LOB ... 在这个"Oracle + PHP Cookbook"HowTo中,您将学习可用的L ...

  6. 对于笔试题--“good and abc”的理解

    今天朋友问了一个面试题,题目如下: public class Example{ String str=new String("good"); char[]ch={'a','b',' ...

  7. 微信小程序开发(1)

    底限,HTML,CSS,JS得会 先过一下官方的文档:https://mp.weixin.qq.com/debug/wxadoc/introduction/index.html?t=20161230 ...

  8. 基于C++的类编程总结

    1. 类中public, protected, private这三个属性的区别: public意味着所有事物都能查询具有该属性的食物.(也即所有人可以在我不知情的情况下,查看我账户里还有多少钱). p ...

  9. hdu 5833 Zhu and 772002 异或方程组高斯消元

    ccpc网赛卡住的一道题 蓝书上的原题 但是当时没看过蓝书 今天又找出来看看 其实也不是特别懂 但比以前是了解了一点了 主要还是要想到构造异或方程组 异或方程组的消元只需要xor就好搞了 数学真的是硬 ...

  10. Linux下的数据监控工具

    Vmstat Vmstat,virtual memmory statistics(虚拟内存统计),主要是对操作系统的内存信息.进程状态.cpu活动等进行监视,但是它不能对某个进程进行深入的分析. Pr ...