http://acm.hdu.edu.cn/showproblem.php?pid=1335

Basically Speaking

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1885    Accepted Submission(s): 729

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
 
Source
 
Recommend
Ignatius.L

 #include<stdio.h>
#include<string.h>
int cmp(int x,int y)
{
int s=,i;
for(i=;i<=y;i++)
s=s*x;
return s;
}
int main()
{
int t,n,s,l,i,r,j,k,p,q;
char str[];
int a[],b[];
while(~scanf("%s",str))
{
s=j=;
scanf("%d%d",&t,&n);
l=strlen(str);
for(i=;i<l;i++)
{
if(str[i]>=''&&str[i]<='')
a[j++]=str[i]-'';
else
a[j++]=str[i]-;
}
k=;
for(i=j-;i>=;i--)
{
r=a[i]*cmp(t,k);
s+=r;
k++;
}
q=;
while(s!=)
{
p=s%n;
b[q++]=p;
s=s/n;
}
for(j=;j<-q;j++)
{
if(q>)
break;
printf(" ");
}
for(i=q-;i>=;i--)
{
if(q>)
{
printf(" ERROR");
break;
}
if(b[i]==)
printf("A");
if(b[i]==)
printf("B");
if(b[i]==)
printf("C");
if(b[i]==)
printf("D");
if(b[i]==)
printf("E");
if(b[i]==)
printf("F");
if(b[i]>=&&b[i]<=)
printf("%d",b[i]);
}
printf("\n");
}
return ;
}
 
 

HDU-1335 Basically Speaking的更多相关文章

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

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1335 Problem Description The Really Neato Calculator ...

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

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

  3. Basically Speaking

    Basically Speaking Time Limit: 2 Sec  Memory Limit: 200 MB Submit: 19  Solved: 11 [Submit][Status][W ...

  4. HDU 1314 Numerically Speaking(大数加减乘除+另类二十六进制互相转换)

    原题代号:HDU 1314 原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1314 Numerically Speaking Time Limit: 2 ...

  5. ZOJ Problem Set - 1334 Basically Speaking ac代码及总结

    这道题目不难,是一道简单的进制转换问题,但是发现了自己两个遗漏的知识点: 1.关于scanf (1)scanf函数在输入时是以回车或者空格作为一次输入的结束 (2)scanf函数在输入字符串的过程中是 ...

  6. HDU——PKU题目分类

    HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...

  7. POJ题目分类(按初级\中级\高级等分类,有助于大家根据个人情况学习)

    本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算 ...

  8. POJ题目细究

    acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  102 ...

  9. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

随机推荐

  1. HDU 4708 Rotation Lock Puzzle(模拟)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4708 题目大意:给定一个方形矩阵,边长为3-10的奇数.每一圈的数字可以沿着顺时针方向和逆时针方向旋转 ...

  2. EF支持复杂类型的实现

    本节,将介绍如何手动构造复杂类型(ComplexType)以及复杂类型的简单操作.通常,复杂类型是指那些由几个简单的类型组合而成的类型.比如:一张Customer表,其中有FristName和Last ...

  3. 【收集整理】Linux下的目录讲解

    Linux下的目录介绍:在Linux系统中,一切东西都是存放在一个唯一的“虚拟文件系统”中的,这个“虚拟文件系统”是树状的结构以一个根目录开始.以文件来表示所有逻辑实体和非逻辑实体,逻辑实体指文件和目 ...

  4. 身份证js验证

    <script type="text/javascript"> //--身份证号码验证-支持新的带x身份证 function isIdCardNo(num) { var ...

  5. java中运算符——进度1

    Class Demo1{    public static void main(String[] args) {        /*        一.逻辑运算法用于连接两个boolean类型的表达式 ...

  6. 压缩代码加速ecshop程序页面加载速度

    由于页面有很多图片,页面加载速度有点慢,本来打算减小图片的体积,后来想想这个后期还得测试下,所以暂时不打算使用google的图片优化工具,先把ecshop生成的html代码压缩下吧 压缩前:首页体积为 ...

  7. JVM内存管理基本概念

    java中是否存在内存泄露? 在Java中,内存泄漏就是存在一些被分配的对象,这些对象有下面两个特点,首先,这些对象是可达的,即在有向图中,存在通路可以与其相连:其次,这些对象是无用的,即程序以后不会 ...

  8. 快速生成json实体类

    读取一个json文件,并与实体相对应: static void Main(string[] args) { string json = ""; FileStream fs = ne ...

  9. C语言头文件书写

    说一下C语言的存储类说明符: 1.Auto       只在块内变量声明中被允许,表示变量具有本地生存期. 2.Extern    出现在顶层或块的外部变量函数与变量声明中,表示声明的对象具有静态生存 ...

  10. caffe之(三)激活函数层

    在caffe中,网络的结构由prototxt文件中给出,由一些列的Layer(层)组成,常用的层如:数据加载层.卷积操作层.pooling层.非线性变换层.内积运算层.归一化层.损失计算层等:本篇主要 ...