-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathURI1199SimpleBaseConversion.java
More file actions
46 lines (40 loc) · 1.18 KB
/
URI1199SimpleBaseConversion.java
File metadata and controls
46 lines (40 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
/**
* See
* <a href="https://www.urionlinejudge.com.br/judge/en/problems/view/1199">Simple
* Base Conversion</a>
*
* @author Brian Yeicol Restrepo Tangarife
*/
public class URI1199SimpleBaseConversion {
static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) throws IOException {
String s;
int N;
while (true) {
s = read();
if (s.matches("0x.*")) {
s = s.substring(2);
out.println(Integer.parseInt(s, 16));
} else {
N = toInt(s);
if (N < 0) {
break;
} else {
out.println("0x" + Integer.toString(N, 16).toUpperCase());
}
}
}
out.close();
}
private static String read() throws IOException {
return in.readLine();
}
private static int toInt(String s) {
return Integer.parseInt(s);
}
}