-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHJ33.java
39 lines (33 loc) · 974 Bytes
/
HJ33.java
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
import java.util.Scanner;
public class HJ33 {
private int N = 4;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
HJ33 mm = new HJ33();
while (in.hasNext()) {
String str = in.next();
String res = mm.tenkan(str);
System.out.println(res);
}
}
public String tenkan(String str)
{
if(str.contains(".")){
String[] arr = str.split("\\.");
long result = 0;
for(int i = 0; i < N; i++){
result = result * 256 + Integer.parseInt(arr[i]);
}
return ""+result;
}
else{
long aa = Long.valueOf(str);
String result = "";
for(int i = 0; i < N; i++){
result = aa % 256 + "." + result;
aa = aa / 256;
}
return result.substring(0,result.length()-1);
}
}
}