Pro.ID21985 TitleConversions Title链接http://10.20.2.8/oj/exercise/problem?problem_id=21985 AC0 Submit0 Ratio- 时间&空间限制描述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 Sample Output sample #1 Source 样例输入sample #1 样例输出sample #1 作者 |