|
| 1 | +```java |
| 2 | +import java.awt.Point; |
| 3 | +import java.io.BufferedReader; |
| 4 | +import java.io.IOException; |
| 5 | +import java.io.InputStreamReader; |
| 6 | +import java.util.StringTokenizer; |
| 7 | + |
| 8 | + |
| 9 | +public class Main { |
| 10 | + |
| 11 | + static final int DAY = 1440; |
| 12 | + static final int NIGHT = 1320; |
| 13 | + static final int MORNING = 480; |
| 14 | + static final int HOUR = 60; |
| 15 | + |
| 16 | + static String[] rawTime; |
| 17 | + static int[] playTimes; |
| 18 | + static int tc, curBill,curTime,playTime; |
| 19 | + |
| 20 | + static StringBuilder sb = new StringBuilder(); |
| 21 | + |
| 22 | + |
| 23 | + public static void main(String[] args) throws IOException { |
| 24 | + init(); |
| 25 | + process(); |
| 26 | + print(); |
| 27 | + } |
| 28 | + |
| 29 | + private static void init() throws IOException { |
| 30 | + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); |
| 31 | + tc = Integer.parseInt(br.readLine()); |
| 32 | + rawTime = new String[tc]; |
| 33 | + playTimes = new int[tc]; |
| 34 | + for (int i = 0; i < tc; i++) { |
| 35 | + StringTokenizer st = new StringTokenizer(br.readLine()); |
| 36 | + rawTime[i] = st.nextToken(); |
| 37 | + playTimes[i] = Integer.parseInt(st.nextToken()); |
| 38 | + } |
| 39 | + |
| 40 | + } |
| 41 | + |
| 42 | + private static void process() throws IOException { |
| 43 | + for (int i = 0; i < tc; i++) { |
| 44 | + System.out.println(); |
| 45 | + String rawTarget = rawTime[i]; |
| 46 | + |
| 47 | + int hour = Integer.parseInt(rawTarget.substring(0,2)); |
| 48 | + int minute = Integer.parseInt(rawTarget.substring(3,5)); |
| 49 | + |
| 50 | + playTime = playTimes[i]; |
| 51 | + curTime = hour * 60 + minute; |
| 52 | + curBill = 0; |
| 53 | + |
| 54 | + while (playTime > 0) { |
| 55 | + if (curTime < MORNING || curTime >= NIGHT) { |
| 56 | + toMorning(); |
| 57 | + } else { |
| 58 | + toNight(); |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + sb.append(curBill).append("\n"); |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + private static void toNight() { |
| 67 | + int leftTimeToNight = NIGHT - curTime; |
| 68 | + if ( leftTimeToNight > playTime) { // 밤에 도달 못함 |
| 69 | + curBill += (playTime/HOUR) * 1000; |
| 70 | + if (playTime%HOUR != 0) curBill += 1000; |
| 71 | + playTime = 0; |
| 72 | + } else { |
| 73 | + if (playTime - leftTimeToNight < 300) { |
| 74 | + curBill += (playTime/HOUR) * 1000; |
| 75 | + if (playTime%HOUR != 0) curBill += 1000; |
| 76 | + playTime = 0; |
| 77 | + } else { |
| 78 | + curBill += (leftTimeToNight/HOUR) * 1000; |
| 79 | + if (leftTimeToNight%HOUR != 0) curBill += 1000; |
| 80 | + playTime -= leftTimeToNight; |
| 81 | + curTime = NIGHT; |
| 82 | + } |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + private static void toMorning() { |
| 87 | + int leftTimeToMorning = MORNING - curTime; |
| 88 | + if ( leftTimeToMorning < 0) leftTimeToMorning += DAY; |
| 89 | + |
| 90 | + if ( leftTimeToMorning >= 300 ) { |
| 91 | + if (playTime >= 300){ |
| 92 | + curBill += 5000; |
| 93 | + playTime -= leftTimeToMorning; |
| 94 | + curTime = MORNING; |
| 95 | + } else { |
| 96 | + curBill += (playTime/HOUR) * 1000; |
| 97 | + if (playTime%HOUR != 0) curBill += 1000; |
| 98 | + playTime = 0; |
| 99 | + } |
| 100 | + } else { |
| 101 | + if(leftTimeToMorning > playTime ) { |
| 102 | + int tempBill = (leftTimeToMorning/HOUR) * 1000; |
| 103 | + if(leftTimeToMorning%HOUR != 0) tempBill += 1000; |
| 104 | + |
| 105 | + curBill += tempBill; |
| 106 | + curTime += (tempBill/1000)*60; |
| 107 | + playTime -= (tempBill/1000)*60; |
| 108 | + } else { |
| 109 | + curBill += (playTime/HOUR) * 1000; |
| 110 | + if (playTime%HOUR != 0) curBill += 1000; |
| 111 | + playTime = 0; |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + if (curTime > DAY) curTime -= DAY; |
| 116 | + |
| 117 | + } |
| 118 | + |
| 119 | + private static void print() { |
| 120 | + System.out.print(sb.toString()); |
| 121 | + } |
| 122 | +} |
| 123 | +``` |
0 commit comments