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. Linq的简单查询

    Ling的简单查询,记在这里防止忘记,以便随时能够查看 List<int> intArr = new List<int>(); || i == select i; List&l ...

  2. [CLR VIA C#] chapter2 building,packaging,deploying, and administering

    今天整理一下 assembly, 总感觉第一章 到 第三章 没怎么仔细看, 导致后面作者说前面说过的, 我就心里不舒服, 前面3章很干很涩, 好好啃啃, 先作一些简单笔记, 最后再来 整体整理, 反正 ...

  3. Python 学习之urllib模块---用于发送网络请求,获取数据(4)

    承接将查询城市编码的结果保存到文件中,以字典的形式保存,目的是为了在查询某个城市的天气的时候,能够通过输入的城市名称,找到对应的城市编码.所以此结果字典的数据结构,就是city={城市名称:城市编码} ...

  4. 《C和指针》章节后编程练习解答参考——6.3

    <C和指针>——6.3 题目: 编写一个函数,把参数字符串中的字符反向排列. 函数原型: void reverse_string(char *string); 要求: 使用指针而不是数组下 ...

  5. 聊聊Web App、Hybrid App与Native App的设计差异

    目前主流应用程序大体分为三类:Web App.Hybrid App. Native App. 一.Web App.Hybrid App.Native App 纵向对比 首先,我们来看看什么是 Web ...

  6. ARM编译器4字节对齐

    (1)我们假设只有一个赋初值的char型全局变量,那么系统会在data区分配一个4字节的存储空间来存储它.实际上,只用了1个字节,但是为了4字节对齐,只好分配4个字节,所以就会有3个字节浪费. (2) ...

  7. 使用EF6.0出现:CS0029 无法将类型“System.Data.Entity.Core.Objects.ObjectContext”隐式转换为“System.Data.Objects.ObjectContext”错误

    这是因为EF6.0重构了一些命名空间后,和VS原有的实体数据模型模板不一致了(ObjectContext context = ((IObjectContextAdapter)dataContext). ...

  8. C# aspnetpager分页

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs& ...

  9. jQuery获取屏幕的宽度

    Javascript: 网页可见区域宽: document.body.clientWidth网页可见区域高: document.body.clientHeight网页可见区域宽: document.b ...

  10. bzoj 1209: [HNOI2004]最佳包裹 三维凸包

    1209: [HNOI2004]最佳包裹 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 160  Solved: 58[Submit][Status] ...