-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLyrics.java
More file actions
47 lines (45 loc) · 1.84 KB
/
Copy pathLyrics.java
File metadata and controls
47 lines (45 loc) · 1.84 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
47
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Lyrics {
public static void adjustTime(In filename, int adj) {
String regex
= "([0-9]{2}):([0-9]{2}):([0-9]{2}).([0-9]{3}).*([0-9]{2}):([0-9]{2}):([0-9]{2}).([0-9]{3})";
Pattern pattern = Pattern.compile(regex);
while (filename.hasNextLine()) {
String line = filename.readLine();
Matcher matcher = pattern.matcher(line);
if (matcher.find()) {
int h1 = Integer.parseInt(matcher.group(1));
int m1 = Integer.parseInt(matcher.group(2));
int s1 = Integer.parseInt(matcher.group(3));
int ms1 = Integer.parseInt(matcher.group(4));
int h2 = Integer.parseInt(matcher.group(5));
int m2 = Integer.parseInt(matcher.group(6));
int s2 = Integer.parseInt(matcher.group(7));
int ms2 = Integer.parseInt(matcher.group(8));
int x = ms1 + adj;
int Ms1 = x % 1000;
x = s1 + x / 1000;
int S1 = x % 60;
x = m1 + x / 60;
int M1 = x % 60;
int H1 = h1 + x / 60;
int xx = ms2 + adj;
int Ms2 = xx % 1000;
xx = s2 + xx / 1000;
int S2 = xx % 60;
xx = m2 + xx / 60;
int M2 = xx % 60;
int H2 = h2 + xx / 60;
System.out.println(H1 + ":" + M1 + ":" + S1 + "," + Ms1 + " --> "
+ H2 + ":" + M2 + ":" + S2 + "," + Ms2);
}
else System.out.println(line);
}
}
public static void main(String[] args) {
In in = new In(args[0]);
int adj = Integer.parseInt(args[1]);
adjustTime(in, adj);
}
}