Basically Speaking

Basically Speaking

Time Limit: 2 Sec  Memory Limit: 200 MB

Submit: 19  Solved: 11

[Submit][Status][Web Board]

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 <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int a,b,l,i;
long long sum;
char ch[10];
int work(char ch)
{
    if(ch>=‘0‘ && ch<=‘9‘) return ch-‘0‘;
     return ch-‘A‘+10;
}
char solve(int k)
{
    if (k<10) return char(k+48);
      return char(k+55);
}
int main()
{
    while(~scanf("%s%d%d",&ch,&a,&b))
    {
        l=strlen(ch);
        sum=0;
        for(int i=0;i<l;i++)
            sum=sum*a+work(ch[i]);
        if (sum==0)
        {
            printf("      0\n");
            continue;
        }
        l=0;
        while(sum>0)
        {
            ch[++l]=solve(sum%b);
            sum=sum/b;
        }
       if (l<=7)
        {
            for(i=1;i<=7-l;i++) printf(" ");
            for(i=l;i>=1;i--) printf("%c",ch[i]);
        }
        else printf("  ERROR");
       printf("\n");
    }
    return 0;
}
时间: 2024-10-11 11:23:28

Basically Speaking的相关文章

杭电 HDU ACM 1335 Basically Speaking

Basically Speaking Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2532    Accepted Submission(s): 959 Problem Description The Really Neato Calculator Company, Inc. has recently hired your team

HDOJ 1335 Basically Speaking(进制转换)

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 c

POJ1546 &amp; HDU 1335 &amp; ZOJ 1334 Basically Speaking(进制转换)

题目链接: POJ:http://poj.org/problem?id=1546 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=1335 ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=334 Description The Really Neato Calculator Company, Inc. has recently hired your team to help

HDU1335_Basically Speaking【水题】

Basically Speaking Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2456    Accepted Submission(s): 931 Problem Description The Really Neato Calculator Company, Inc. has recently hired your team

北大ACM题库习题分类与简介(转载)

在百度文库上找到的,不知是哪位大牛整理的,真的很不错! zz题 目分类 Posted by fishhead at 2007-01-13 12:44:58.0 -------------------------------------------------------------------------------- acm.pku.edu.cn 1. 排序 1423, 1694, 1723, 1727, 1763, 1788, 1828, 1838, 1840, 2201, 2376, 23

POJ百道水题列表

以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight Moves1101 Gamblers1204 Additive equations 1221 Risk1230 Legendary Pokemon1249 Pushing Boxes 1364 Machine Schedule1368 BOAT1406 Jungle Roads1411 Annive

ACM训练方案-POJ题目分类

ACM训练方案-POJ题目分类 博客分类: 算法 ACM online Judge 中国: 浙江大学(ZJU):http://acm.zju.edu.cn/ 北京大学(PKU):http://acm.pku.edu.cn/JudgeOnline/ 杭州电子科技大学(HDU):http://acm.hdu.edu.cn/ 中国科技大学(USTC):http://acm.ustc.edu.cn/ 北京航天航空大学(BUAA)http://acm.buaa.edu.cn/oj/index.php 南京

转载:poj题目分类(侵删)

转载:from: POJ:http://blog.csdn.net/qq_28236309/article/details/47818407 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K–0.50K:中短代码:0.51K–1.00K:中等代码量:1.01K–2.00K:长代码:2.01K以上. 短:1147.1163.1922.2211.2215.2229.2232.2234.2242.2245.2262.2301.2309.2313.2334.2346.2348

HackerRank - &quot;Building a Smart IDE: Programming Language Detection&quot;

So fun! It connects algorithm(regex) with real world usages! So basically speaking, C:pointer syntax, #include\scanf\typedef; Java: import\public class syntax\try-catch syntax; Python: def syntax\special print syntax. And BTW, if you are working on r