-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathMockery.java
More file actions
53 lines (46 loc) · 1.64 KB
/
Copy pathMockery.java
File metadata and controls
53 lines (46 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package mockery;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Mockery {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(new FileReader("input.txt"));
int[][] matrix = new int[0][];
int row = -1;
while (sc.hasNextLine()) {
String str = sc.nextLine();
if (row == -1) {
int size = Integer.parseInt(str);
matrix = new int[size][size];
} else {
StringTokenizer st = new StringTokenizer(str, " ");
int column = 0;
while (st.hasMoreTokens()){
matrix[row][column] = Integer.parseInt(st.nextToken());
column++;
}
}
row++;
}
int shortestWay = Integer.MAX_VALUE;
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix.length; j++) {
if (i < j) {
for (int k = 0; k < matrix.length; k++) {
if (matrix[i][j] != 0 && matrix[i][k] != 0 && matrix[j][k] != 0) {
int sumRouds = matrix[i][j] + matrix[i][k] + matrix[j][k];
if (shortestWay > sumRouds) {
shortestWay = sumRouds;
}
}
}
}
}
}
PrintWriter out = new PrintWriter(System.out);
out.println(shortestWay);
out.flush();
}
}