Wednesday, August 5, 2015

UVa 10473 - Simple Base Conversion

// UVa 10473 - Simple Base Conversion
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			String line = scanner.nextLine();
			BigInteger big;
			boolean hex = true;
			if (line.length() > 2 && line.charAt(0) == '0' && line.charAt(1) == 'x') {
				line = line.substring(2);
				big = new BigInteger(line, 16);
				hex = false;
			} else
				big = new BigInteger(line);
			if (big.compareTo(BigInteger.ZERO) < 0)
				break;
			if (hex)
				System.out.println("0x" + big.toString(16).toUpperCase());
			else
				System.out.println(big);
		}

	}
}

No comments:

Post a Comment