Programming contests

ACM ICPC programozó csapatverseny, házi forduló, 2015. október 21.

October 21, 2015 10:00 AM – October 21, 2015 3:00 PM

Simple Base Conversion

In this problem, you are asked to write a simple base conversion program. You will be given a hexadecimal or decimal integer number as input. You will have to output the corresponding decimal or hexadecimal number. Hexadecimal numbers always start with “0x”, all other numbers are to be considered as decimal numbers. There will be no invalid numbers in the input.

Input Specification

The input contains several lines of input. Each line contains a single non-negative number, which may be a decimal or hexadecimal number as explained in the problem statement. The decimal value of this number will be less than 231. A line containing a negative decimal number terminates the input. This number should not be processed. Input numbers will contain no space within them.

Output Specification

For each line of input (except the last one), produce one line of output. This line should contain the decimal or hexadecimal representation of the corresponding hexadecimal or decimal number. Like in the input, hexadecimal numbers in the output should be preceded by “0x”. Moreover, letters representing hexadecimal digits should be uppercase.

Sample Input

  1. 4
  2. 7
  3. 44
  4. 0x80685
  5. -1
download as text file

Output for Sample Input

  1. 0x4
  2. 0x7
  3. 0x2C
  4. 525957
download as text file
University of Debrecen; Faculty of Informatics; v. 03/01/2019