-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBase.java
More file actions
39 lines (32 loc) · 749 Bytes
/
Copy pathBase.java
File metadata and controls
39 lines (32 loc) · 749 Bytes
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
// Success in 0.18s
import java.util.Scanner;
public class Base{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i = 1; i <= n; i++) {
sc.nextInt();
int v = sc.nextInt();
System.out.printf("%d %d %d %d\n", i, fromOktal(Integer.toString(v)), v, fromHex(v));
}
sc.close();
}
private static int fromOktal(String v){
for(char c : v.toCharArray())
if (c == '9' || c == '8')
return 0;
return Integer.parseInt(v, 8);
}
private static int fromHex(int v){
int ret = 0;
int p = 1;
while(v > 0){
int n = v % 10;
v -= n;
v /= 10;
ret += n * p;
p *= 16;
}
return ret;
}
}