21985_Conversions

2022-5-16 18:20| 发布者: Hocassian| 查看: 24| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-8950616327400-Problem List-采集的数据-后羿采集器.html

Pro.ID

21985

Title

Conversions

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21985

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    The BINEG computer your company recently bought is using the negabinary (or base -2) system instead of the more common binary (or base 2) system. To use the beast, you need to convert your existing data to the new representation. And, in order for the output to make any sense for the rest of the world, you also have to translate it back to the more conventional system.

    Your boss is a guy who likes to solve problems "once and for all". So, he has asked you to develop a universal converter , from any system (using positive or negative base) to any other (again, using positive or negative base), and it should work on numbers of almost any size as well.

    More formally, for any B (positive or negative), the digits used to write numbers in base B are 0...|B|-1, and the sequence of digits ANAN-1...A1A0 always represents the value ANBN+AN-1BN-1+...+A1B+A0. The first letters of the Latin alphabet are used as digits after 9 in case |B| > 10.

    输入

    The first line of the input contains two integers, B1 and B2 (2 ≤ |B1|, |B2| ≤ 16), where B1 is the input base and B2 is the output base. The second line of the file contains a non-negative integer value written in base B1 that may consist of up to 100 digits. Only uppercase letters are used in case |B1| > 10.

    输出

    Description

    The BINEG computer your company recently bought is using the negabinary (or base -2) system instead of the more common binary (or base 2) system. To use the beast, you need to convert your existing data to the new representation. And, in order for the output to make any sense for the rest of the world, you also have to translate it back to the more conventional system.

    Your boss is a guy who likes to solve problems "once and for all". So, he has asked you to develop a universal converter , from any system (using positive or negative base) to any other (again, using positive or negative base), and it should work on numbers of almost any size as well.

    More formally, for any B (positive or negative), the digits used to write numbers in base B are 0...|B|-1, and the sequence of digits ANAN-1...A1A0 always represents the value ANBN+AN-1BN-1+...+A1B+A0. The first letters of the Latin alphabet are used as digits after 9 in case |B| > 10.

    Input

    The first line of the input contains two integers, B1 and B2 (2 ≤ |B1|, |B2| ≤ 16), where B1 is the input base and B2 is the output base. The second line of the file contains a non-negative integer value written in base B1 that may consist of up to 100 digits. Only uppercase letters are used in case |B1| > 10.

    Output

    The output consist of exactly one line containing the value given on the second line of the input file, but represented in base B2. Only uppercase letters should be used in case |B2| > 10 and the output should have minimal length in any case.

    Sample Input

    sample #1
    2 16
    11111


    sample #2
    -2 16
    11111

    Sample Output

    sample #1
    1F

    sample #2
    B

    Source

    样例输入

    sample #1
    2 16
    11111


    sample #2
    -2 16
    11111

    样例输出

    sample #1
    1F

    sample #2
    B

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部