NCPC25 finished
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
package com.kattis.ncpc25.log.rider;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.MissingFormatArgumentException;
|
||||
|
||||
public class C {
|
||||
|
||||
public static final int MINUTES_IN_A_DAY = 1_440;
|
||||
|
||||
public static void main(String[] args) throws Exception{
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
|
||||
String start = in.readLine();
|
||||
String end = in.readLine();
|
||||
|
||||
String out = countTime(start, end);
|
||||
System.out.println(out);
|
||||
}
|
||||
|
||||
public static String countTime(String start, String end)
|
||||
{
|
||||
if(start.equalsIgnoreCase(end))
|
||||
{
|
||||
return "7 days";
|
||||
}
|
||||
|
||||
int startTime = formatedTimeToMin(start);
|
||||
int endTime = formatedTimeToMin(end);
|
||||
|
||||
if(endTime < startTime)
|
||||
{
|
||||
endTime += MINUTES_IN_A_DAY*7;
|
||||
}
|
||||
|
||||
int totalTime = endTime-startTime;
|
||||
|
||||
int days = totalTime / MINUTES_IN_A_DAY;
|
||||
int hours = (totalTime - (days * MINUTES_IN_A_DAY)) / 60;
|
||||
int minutes = (totalTime - (days * MINUTES_IN_A_DAY) - (hours * 60));
|
||||
|
||||
int components = 0;
|
||||
if(days > 0)
|
||||
{
|
||||
components += 1;
|
||||
}
|
||||
if(hours > 0)
|
||||
{
|
||||
components += 1;
|
||||
}
|
||||
if(minutes > 0)
|
||||
{
|
||||
components += 1;
|
||||
}
|
||||
|
||||
StringBuilder out = new StringBuilder();
|
||||
if(days > 0)
|
||||
{
|
||||
out.append(days).append(" day").append((days == 1?"":"s"));
|
||||
}
|
||||
if(hours > 0)
|
||||
{
|
||||
if(!out.isEmpty())
|
||||
{
|
||||
if(components == 2)
|
||||
{
|
||||
out.append(" and ");
|
||||
}
|
||||
else {
|
||||
out.append(", ");
|
||||
}
|
||||
}
|
||||
out.append(hours).append(" hour").append((hours == 1?"":"s"));
|
||||
}
|
||||
if(minutes > 0)
|
||||
{
|
||||
if(!out.isEmpty())
|
||||
{
|
||||
if(components == 2)
|
||||
{
|
||||
out.append(" and ");
|
||||
}
|
||||
else {
|
||||
out.append(", ");
|
||||
}
|
||||
}
|
||||
out.append(minutes).append(" minute").append((minutes == 1?"":"s"));
|
||||
}
|
||||
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
public static int formatedTimeToMin(String formated)
|
||||
{
|
||||
String day, time;
|
||||
day = formated.split(" ")[0];
|
||||
time = formated.split(" ")[1];
|
||||
int min = 0;
|
||||
|
||||
min += switch (day) {
|
||||
case "Mon" -> MINUTES_IN_A_DAY;
|
||||
case "Tue" -> MINUTES_IN_A_DAY*2;
|
||||
case "Wed" -> MINUTES_IN_A_DAY*3;
|
||||
case "Thu" -> MINUTES_IN_A_DAY*4;
|
||||
case "Fri" -> MINUTES_IN_A_DAY*5;
|
||||
case "Sat" -> MINUTES_IN_A_DAY*6;
|
||||
case "Sun" -> MINUTES_IN_A_DAY*7;
|
||||
default -> 0;
|
||||
};
|
||||
|
||||
String hour = time.split(":")[0];
|
||||
String minute = time.split(":")[1];
|
||||
|
||||
min += Integer.parseInt(minute);
|
||||
min += Integer.parseInt(hour)*60;
|
||||
|
||||
return min;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user