fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. //import java.util.regex.*;
  7. import java.util.regex.Matcher;
  8. import java.util.regex.Pattern;
  9.  
  10. /* Name of the class has to be "Main" only if the class is public. */
  11. class Ideone
  12. {
  13. public static void main (String[] args) throws java.lang.Exception
  14. {
  15. Scanner myObj = new Scanner(System.in); // Create a Scanner object
  16.  
  17. //stackoverflow/questions/2296685/how-to-read-input-with-multiple-lines-in-java
  18. //stackoverflow/questions/56887493/how-to-take-multi-line-input-in-java search:HashmatWarrior
  19. while(myObj.hasNext()) // see if there's more
  20. {
  21. String schedule = myObj.nextLine(); // Read user input (from w3schools/java/java_user_input.asp)
  22.  
  23. //stackoverflow/questions/10004066/java-splitting-an-input-file-by-colons
  24. String schedParts[] = schedule.split("\t");
  25. String workDay=schedParts[0];
  26.  
  27. if(schedParts.length>1)
  28. {
  29. String workDate=schedParts[1];
  30. System.out.print(workDay+" "+workDate+", ");
  31.  
  32. if(schedParts.length>2)
  33. {
  34. String workTime=schedParts[2];
  35. String workLength=schedParts[3];
  36.  
  37. //w3 schools
  38. String matchMe="(pm)|( O)|( )";
  39. Pattern pattern = Pattern.compile(matchMe);
  40. Matcher matcher = pattern.matcher(workTime);
  41. workTime = matcher.replaceAll("");
  42. boolean matchFound = matcher.find();
  43. System.out.print(workTime+", ");
  44. }
  45. System.out.println();
  46. }
  47.  
  48. else if(schedParts.length==1)
  49. {
  50. System.out.println();
  51. }
  52. }
  53. }
  54. }
Success #stdin #stdout 0.2s 61120KB
stdin
Sun	2/2	4:30pm - 9:30pm O	5:00
Mon	2/3	5:30pm - 10:30pm O	5:00
Tue	2/4	5:30pm - 10:30pm O	5:00
Wed	2/5		
Thu	2/6		
Fri	2/7		
Sat	2/8	

Sun	2/9	4:30pm - 9:30pm O	5:00
Mon	2/10	5:30pm - 10:30pm O	5:00
Tue	2/11	5:30pm - 10:30pm O	5:00
Wed	2/12		
Thu	2/13		
Fri	2/14	5:30pm - 10:30pm O	5:00
Sat	2/15	
stdout
Sun 2/2, 4:30-9:30, 
Mon 2/3, 5:30-10:30, 
Tue 2/4, 5:30-10:30, 
Wed 2/5, 
Thu 2/6, 
Fri 2/7, 
Sat 2/8, 

Sun 2/9, 4:30-9:30, 
Mon 2/10, 5:30-10:30, 
Tue 2/11, 5:30-10:30, 
Wed 2/12, 
Thu 2/13, 
Fri 2/14, 5:30-10:30, 
Sat 2/15,