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. swift-03-数据类型转换

    //  main.swift //  05-数据类型的转换 // //  Created by wanghy on 15/8/9. //  Copyright (c) 2015年 wanghy. Al ...

  2. 如何使用Json-lib

    数组与List.Collection等都用JSONArray解析 boolean[] boolArray = new boolean[]{true,false,true}; JSONArray jso ...

  3. clr介绍

    CLR(公用语言运行时)和Java虚拟机一样也是一个运行时环境,它负责资源管理(内存分配和垃圾收集),并保证应用和底层操作系统之间必要的分离..NET提供了一个运行时环境,叫做公用语言运行时(Comm ...

  4. 菜鸟的MySQL学习笔记(二)

    3-1约束: 1.约束保证数据的完整性和一致性: 2.约束分表级约束(两个或两个个以上字段的约束)和列级约束(一个字段约束): 3.NOT NULL       非空: PRIMARY KEY     ...

  5. 点击listview 的列头对其item进行自动排序

    若要自定义排序顺序,必须编写一个实现 IComparer 接口的类,并将 ListViewItemSorter 属性设置为该类的一个对象.当设置 ListViewItemSorter 属性值时,将自动 ...

  6. 【python】aassert 断言

    语法 : assert 3>4 结果Traceback (most recent call last): File "<pyshell#0>", line 1, ...

  7. Python的面向对象1

    今天,我们来介绍Python的面向对象编程,其实面向对象并不陌生,在C++  ,Java  ,PHP中也有大量使用! 好了,我们来步入正题! 那什么是面向对象编程呢? 1. 面向对象编程是一种程序设计 ...

  8. 重复数据插入unique列时,锁加在哪?

    1.测试目的 当插入重复数据到有unique索引的表中时,采用何种加锁机制. 2.测试思路 利用10046确定是什么操作导致加锁阻塞了进程: dump锁定前最近一次操作的块结构来分析加锁机制. 3.测 ...

  9. load-store/register-memory/register-plus-memory比较

    在理解ARM的load-store架构时,我在百度上搜索了很长时间,但是始终找不到一篇像样的中文文章.最后,在用谷歌搜索的英文网站上终于找到了一些蛛丝马迹.让我们先看一下一篇英文资料. Process ...

  10. Eclipse中的add jars和add external jars有什么区别(转载)

    转载自:http://blog.csdn.net/yasi_xi/article/details/12772457 add jars和add external jars有什么区别?   add ext ...