Skip to content

Commit a3e0cf8

Browse files
committed
fix bugs in MinimizingLateness(TheAlgorithms#765)
1 parent 1ebe496 commit a3e0cf8

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

MinimizingLateness/MinimizingLateness.java

+13-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package MinimizingLateness;
22

3-
import java.io.*;
4-
import java.util.*;
3+
4+
import java.io.BufferedReader;
5+
import java.io.FileReader;
6+
import java.io.IOException;
7+
import java.util.StringTokenizer;
58

69
public class MinimizingLateness {
710

@@ -18,23 +21,23 @@ public Schedule(int t, int d) {
1821
}
1922

2023
public static void main(String[] args) throws IOException {
21-
// TODO Auto-generated method stub
2224
StringTokenizer token;
2325

24-
String ch;
25-
BufferedReader in = new BufferedReader(new FileReader("input.txt"));
26-
int indexCount; // size of array index
27-
ch = in.readLine();
28-
indexCount = Integer.parseInt(ch); // The first line specifies the size of the operation (= the size of the array)
26+
BufferedReader in = new BufferedReader(new FileReader("MinimizingLateness/lateness_data.txt"));
27+
String ch = in.readLine();
28+
if (ch == null || ch.isEmpty()) {
29+
return;
30+
}
31+
int indexCount = Integer.parseInt(ch);
2932
System.out.println("Input Data : ");
3033
System.out.println(indexCount); // number of operations
31-
Schedule array[] = new Schedule[indexCount]; // Create an array to hold the operation
34+
Schedule[] array = new Schedule[indexCount]; // Create an array to hold the operation
3235
int i = 0;
3336
while ((ch = in.readLine()) != null) {
3437
token = new StringTokenizer(ch, " ");
3538
// Include the time required for the operation to be performed in the array and the time it should be completed.
3639
array[i] = new Schedule(Integer.parseInt(token.nextToken()), Integer.parseInt(token.nextToken()));
37-
i++; // 다음 인덱스
40+
i++;
3841
System.out.println(array[i - 1].t + " " + array[i - 1].d);
3942
}
4043

0 commit comments

Comments
 (0)