Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import javax.swing.text.StyledEditorKit.ForegroundAction;
public class Problem1 {
public static void main(String[] args) {
//Scanner input=new Scanner (System.in);
//String str[];
//int index =str.indexOf("End");
/*ArrayList<String> result = new ArrayList<String>();
result.addAll(Arrays.asList(input.nextLine().split("\\s+")));
int lenth1= result.size();
System.out.println(lenth1);*/
Scanner scanner = new Scanner(System.in);
//System.out.println("Enter block size");
String str1="";
String line="";
String end="End";
//int n=input.nextInt();
//System.out.println();
int count=0;
ArrayList<Object> list = new ArrayList<>();
//(!hairList.equals(end))
while(!str1.equals(end)){
str1=scanner.nextLine();
list.add(str1);
count++;
};
//System.out.println(count);
//String str[count];
// String subString=str.substring(0,count);
//System.out.println(subString);
String[] subString = new String[list.size()];
//String[] arr = list.toArray(new String[list.size()]);
subString = list.toArray(subString);
//for(String s : subString)
// System.out.println(s);
int hours=0;
int min=0;
int lengthSub=subString.length;
int durLen=lengthSub*2-1;
String[] AllDurations=new String[durLen];
//String[] AllDurations=list.subString("[ ,.]+");
int p=0;
//int q=p+2;
for (int i = 0,a1=0,a2=1; i < subString.length-1; i++,a1=a2+1,a2=a2+2) {
AllDurations[a1]=subString[i].substring(p,p+2);
AllDurations[a2]=subString[i].substring(p+3,p+5);
System.out.println(AllDurations[a1]);
System.out.println(AllDurations[a2]);
}
//=subString.split("[ ,:]+");
int length=AllDurations.length;
System.out.println(AllDurations[3]);
int[] IntDurations=new int[length];
for (int i = 0; i < length; i++) {
IntDurations[i]= Integer.parseInt(AllDurations[i]);
//System.out.println(IntDurations[i]);
}
//System.out.println(duration);
for (int i = 0,j=1; i < length; i+=2,j+=2) {
hours=hours+IntDurations[i];
min+=IntDurations[j];
}
int realHours=hours+min/60;
int realMin=min%60;
System.out.println(realHours+":"+realMin);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.