-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProb08.java
More file actions
68 lines (67 loc) · 1.59 KB
/
Prob08.java
File metadata and controls
68 lines (67 loc) · 1.59 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//Prob08:
/*
Suresh creates new playlists as often as he sneezes (he's quite allergic.)
He keeps forgetting how to find the total length of each list.
Can you calculate it?
Input
The first line of input is an integer N, the number of songs in the list.
The next N lines contain the length of each song in MM:SS format (or M:SS if M is less than 10).
The total time will be less than 1 hour.
5
3:05
2:06
9:59
1:01
1:15
Output
Print the total time of the list in MM:SS format. If less than 10 minutes, print M:SS format.
17:26
Additional Examples
Input 1 Output 1 Input 2 Output 2
4 9:06 3 59:59
1:08 4:04
2:59 22:22
3:56 33:33
1:03
*/
import java.util.Scanner;
import java.util.ArrayList;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ArrayList<String> min = new ArrayList<>();
ArrayList<String> sec = new ArrayList<>();
int times = sc.nextInt();
for(int j=0; j<times+1; j++){
String str = sc.nextLine();
String array1[]= str.split(":");
for (int i = 0; i<array1.length; i++){
if(i%2==0){
min.add(array1[i]);
}
if(i%2==1){
sec.add(array1[i]);
}
}
}
min.remove(0);
int minsum=0;
int secsum=0;
for(int i=0;i<min.size();i++){
minsum+=Integer.parseInt(min.get(i));
}
for(int i=0;i<sec.size();i++){
secsum+=Integer.parseInt(sec.get(i));
}
while(secsum>60){
minsum ++;
secsum-=60;
}
if(secsum<10){
System.out.println(minsum + ":" + "0" +secsum);
}
else{
System.out.println(minsum + ":" + secsum);
}
}
}