-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbabylonian.java
36 lines (34 loc) · 1.09 KB
/
babylonian.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
import java.io.*;
import java.util.*;
import java.lang.Math;
public class babylonian
{
public static void main(String[] args) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int n = Integer.parseInt(in.readLine());
for(int i = 0; i < n; i++) {
String input = in.readLine();
String num = "";
int pow = 0;
long sum = 0;
for(int j = input.length(); j > 0; j--) {
String temp = input.substring(j - 1, j);
if(temp.equals(",")) {
if(num.equals("")) {
pow++;
continue;
}
else sum += (Integer.parseInt(num) * Math.pow(60, pow));
pow++;
num = "";
temp = "";
}
num = temp + num;
if(j == 1 && !num.equals("")) sum += (Integer.parseInt(num) * Math.pow(60, pow));
}
out.println(sum);
}
out.close();
}
}