1. 


/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem #10473 (Simple Base Conversion)
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=16&page=show_problem&problem=1414
*
* @author Christian Posselt
* @author Jonathan Schubert
* @version 1.1, 05/11/2009
*
* Status : Accepted
* Runtime: 0.448
*/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main
{
public static void main(String... args) throws IOException
{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
StringBuilder builder = new StringBuilder();
while(true)
{
String str= bf.readLine();
if(str.contains("-")) //negative Number finish program
break;
if(str.contains("x")) //user input is an hex number
builder.append(Long.valueOf(str.substring(2,str.length()),16)+"\n");
else //user input is an decimal number
builder.append("0x"+Long.toHexString(Integer.parseInt(str)).toString().toUpperCase()+"\n");
}
System.out.print(builder.toString());
}
}

2.

/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem #10473 - (Simple Base Conversion)
*
*
* @author Fabian Seidl
* @author Marcel Sachse
* @version 1.0, 13.05.2009
*
* Status : Accepted
* Runtime: 1.160
*/


import java.io.BufferedInputStream;
import java.util.Scanner;



public class Main {

public static void main(String[] args)
{
BufferedInputStream bin = new BufferedInputStream(System.in);
Scanner scanner = new Scanner(bin);




String input = scanner.next();

while(scanner.hasNext()&&!input.equals("-1"))
{
if(input.startsWith("0x"))
{
int convDec=0;
input=(String)input.subSequence(2, input.length());

int i=0;
while(i<input.length())
{
int val=0;
char digit=input.charAt((input.length()-i)-1);
if(digit>'9')val=(digit-'A')+10;
else
{
val=(digit-'0');
}
convDec+=val*(1<<(i*4));
i++;
}
System.out.println(convDec);

convDec=0;
}
else
{
String tmp="";
String convHex="";
int number = Integer.parseInt(input);
int rest=0;
while(number!=0)
{
rest=number%16;
//number-=rest;
number/=16;
switch(rest)
{
case 10:tmp += "A";break;
case 11:tmp += "B";break;
case 12:tmp += "C";break;
case 13:tmp += "D";break;
case 14:tmp += "E";break;
case 15:tmp += "F";break;
default :tmp += rest;
}
convHex=tmp+convHex;
tmp="";
}
System.out.println("0x"+convHex);
}

input = scanner.next();
}
}
}

3.

/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem: Simple Base Conversion (10473)
* @author Christian Mitterreiter
* @author Rolf Luigs
* @version 1.0, 05/12/2009
* Status : Accepted
* Runtime: 0.848
*/


import java.util.Scanner;

public class Main {

public static long toDezimal(String in) {
in = in.substring(2);
int laenge = in.length();
long out = 0;
long index = 0;
int aktuelleZiffer = 0;
for(int i = laenge-1; i>=0;i--) { //Beginnend bei der letzten Ziffer der Zahl
if(in.charAt(i) >= 48 && (in.charAt(i)) <= 57) {
aktuelleZiffer = in.charAt(i)-48;
}
else {
if(in.charAt(i) == 'A') aktuelleZiffer = 10;
if(in.charAt(i) == 'B') aktuelleZiffer = 11;
if(in.charAt(i) == 'C') aktuelleZiffer = 12;
if(in.charAt(i) == 'D') aktuelleZiffer = 13;
if(in.charAt(i) == 'E') aktuelleZiffer = 14;
if(in.charAt(i) == 'F') aktuelleZiffer = 15;
}
out+= aktuelleZiffer*Math.pow(16,index ); //Umrechung in Dezimal
index++;
}
return out;
}


public static StringBuilder toHexadezimal(String in) {
StringBuilder ret = new StringBuilder("0x");
long input = Long.parseLong(in);
long rest = 0;

do {
rest = input % 16;
input = (int)(input/16);

if(rest <= 9) ret.insert(2, rest); //Wenn der Rest, welcher bei der Teilung blieb, kleiner als 10 ist, wird er "vorne" am String angehängt
else { //Wenn der Rest >9, wird der entsprechende Buchstabe angehängt

if(rest == 10) ret.insert(2, 'A');
if(rest == 11) ret.insert(2, 'B');
if(rest == 12) ret.insert(2, 'C');
if(rest == 13) ret.insert(2, 'D');
if(rest == 14) ret.insert(2, 'E');
if(rest == 15) ret.insert(2, 'F');
}
}
while(input !=0); //Dieser Vorgang läuft so lange, bis sich die Zahl nicht mehr ganzzahlig teilen lässt
return ret;
}


public static void main(String[] args) {

Scanner sc = new Scanner(System.in);
String input = sc.next();

while(input.charAt(0) != '-') { //Abbruch bei negativer Zahl

if(input.length() >1) {
if(input.charAt(1) == 'x') { //Wenn die Zahl mehrstellig ist und das Zweite Zeichen ein 'x' ist, handelt es sich um eine Hex-Zahl
System.out.println(toDezimal(input));
}
else System.out.println(toHexadezimal(input)); //ist die Zahl mehrstellig und ohne 'x' ist sie Dezimal
}

else System.out.println(toHexadezimal(input)); //Wenn die Zahl nur eine Stelle hat, kann sie nur Dizimal sein

input = sc.next();
}
}
}


4.

/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem 10473 Simple Base Conversion
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=16&problem=1414&mosmsg=Submission+received+with+ID+7130445
* @author Miesel Christoph
* @author Seilbeck Robert
* @author Wolfram Andre
* @version 3.0 15.05.2009
*
* Status : Accepted
* Runtime: 0.884
*/

import java.io.*;

public class SimpleConversion
{
public static void main(String[] args) throws Exception
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder(reader.readLine());
StringBuilder hexErg = new StringBuilder();
int dezErg = 0;
int counter = -1;
while(true)
{
if(sb.length() > 1 && sb.charAt(0) == '0' && sb.charAt(1) == 'x')
{

counter = -1;
sb.delete(0, 2);

if(sb.toString() == "0")
{
System.out.println("0");
counter = -1;
hexErg = new StringBuilder();
dezErg = 0;
sb = new StringBuilder(reader.readLine());
continue;
}
for(int i = sb.length()-1; i>=0; i--)
{
counter++;



switch(sb.charAt(i))
{
case 'A':
dezErg += (10)*Math.pow(16,counter);
break;
case 'B':
dezErg += (11)*Math.pow(16,counter);
break;
case 'C':
dezErg += (12)*Math.pow(16,counter);
break;
case 'D':
dezErg += (13)*Math.pow(16,counter);
break;
case 'E':
dezErg += (14)*Math.pow(16,counter);
break;
case 'F':
dezErg += (15)*Math.pow(16,counter);
break;
default:
dezErg += (sb.charAt(i)-48)*Math.pow(16,counter);
break;
}
}
System.out.println(dezErg+"");
}
else
{
if(Integer.parseInt(sb.toString()) < 0)
break;
if(Integer.parseInt(sb.toString()) == 0)
{
System.out.println("0x0");
counter = -1;
hexErg = new StringBuilder();
dezErg = 0;
sb = new StringBuilder(reader.readLine());
continue;
}
int help = Integer.parseInt(sb.toString());
hexErg.append("0x");
while(help >15)
{
int hex = help % 16;
switch(hex)
{
case 10:
hexErg.insert(2, "A");
break;
case 11:
hexErg.insert(2, "B");
break;
case 12:
hexErg.insert(2, "C");
break;
case 13:
hexErg.insert(2, "D");
break;
case 14:
hexErg.insert(2, "E");
break;
case 15:
hexErg.insert(2, "F");
break;
default:
hexErg.insert(2, hex);
}
help/=16;
}
switch(help)
{
case 10:
hexErg.insert(2, "A");
break;
case 11:
hexErg.insert(2, "B");
break;
case 12:
hexErg.insert(2, "C");
break;
case 13:
hexErg.insert(2, "D");
break;
case 14:
hexErg.insert(2, "E");
break;
case 15:
hexErg.insert(2, "F");
break;
default:
hexErg.insert(2, help);
}
System.out.println(hexErg);
}
counter = -1;
hexErg = new StringBuilder();
dezErg = 0;
sb = new StringBuilder(reader.readLine());
}

}
}

5.

/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem #10473 Simple Base Conversion
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=16&page=show_problem&problem=1414
*
* @author Franz Mathauser, Rolf Schirm, Markus Mohr
* @version 1.0, 5/18/2009
*
* Status : Accepted
* Runtime: 0.660
*/



import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;



public class Main {

public static void main(String...args) throws IOException{

BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

while( true){
String line = reader.readLine();
long dez = 0;

// System.out.println(line.substring(0,2));
if(line.length()< 2 || !line.substring(0,2).equals("0x")){

if( Integer.parseInt(line) < 0 )
break;

System.out.println("0x"+Integer.toHexString(Integer.parseInt(line)).toUpperCase());
}

else{

for(int i = 2; i < line.length(); i++){
switch ( line.charAt(i)){
case 'A' : dez += 10;
break;
case 'B' : dez += 11;
break;
case 'C' : dez += 12;
break;
case 'D' : dez += 13;
break;
case 'E' : dez += 14;
break;
case 'F' : dez += 15;
break;
default : dez+= Integer.parseInt(line.charAt(i)+"");
}
dez *= 16;
}
dez /= 16;

System.out.println(dez);
}

// Integer.toHexString(i)


}
}

}