Adding some more judges, here and there.
[andmenj-acm.git] / NEERC / database / database_ia.java
blob30e0069266a0bbefba0918ffa1301f4ab820958a
1 import java.io.*;
2 import java.util.*;
4 /**
5 * @author Iskander Akishev
6 */
7 public class database_ia implements Runnable {
9 private static final String FILE_NAME = "database";
11 public void run() {
12 try {
13 solve();
14 } catch (Throwable t) {
15 t.printStackTrace();
16 System.exit(1);
20 private BufferedReader in;
21 private PrintWriter out;
23 private void solve() throws Exception {
24 in = new BufferedReader(new FileReader(FILE_NAME + ".in"));
25 out = new PrintWriter(new File(FILE_NAME + ".out"));
27 StringTokenizer st = new StringTokenizer(in.readLine());
28 int n = Integer.parseInt(st.nextToken());
29 int m = Integer.parseInt(st.nextToken());
31 String[][] rows = new String[n][m + 1];
33 for (int i = 0; i < n; i++) {
34 String[] r = in.readLine().split(",");
35 System.arraycopy(r, 0, rows[i], 0, m);
36 rows[i][m] = Integer.toString(i + 1);
39 boolean found = false;
40 LOOP: for (int j = 0; j < m; j++) {
41 for (int k = j + 1; k < m; k++) {
42 final int jj = j;
43 final int kk = k;
44 Arrays.sort(rows, new Comparator<String[]>() {
45 public int compare(String[] o1, String[] o2) {
46 int res = o1[jj].compareTo(o2[jj]);
47 if (res == 0) res = o1[kk].compareTo(o2[kk]);
48 return res;
50 });
52 for (int i = 1; i < n; i++) {
53 if (rows[i - 1][j].equals(rows[i][j]) &&
54 rows[i - 1][k].equals(rows[i][k]))
56 found = true;
57 out.println("NO");
58 out.println(rows[i - 1][m] + " " + rows[i][m]);
59 out.println((j + 1) + " " + (k + 1));
60 break LOOP;
66 if (!found) {
67 out.println("YES");
70 in.close();
71 out.close();
74 public static void main(String[] args) {
75 new Thread(new database_ia()).start();