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. T o 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 data are to be read from standard input. The first line of each testdata
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.
for each testcase, output data should be written to standard output and 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.
2 16 11111 -2 16 11111
1F B
Migrated from old NTUJ.
icpc2008, neerc west
No. | Testdata Range | Score |
---|