4 public class database_rs
implements Runnable
{
5 private BufferedReader in
;
6 private PrintWriter out
;
8 private void check(boolean expr
, String msg
) {
14 private void checkBounds(int n
, int low
, int hi
, String nStr
) {
15 check((low
<= n
) && (n
<= hi
), nStr
+ " is not in [" + low
+ ", " + hi
+ "]");
18 private class Row
implements Comparable
<Row
> {
22 public int compareTo(Row that
) {
29 return num
- that
.num
;
33 public boolean equals(Object o
) {
35 return (u
== that
.u
) && (v
== that
.v
) && (num
== that
.num
);
39 private void solve() throws IOException
{
40 StringTokenizer st
= new StringTokenizer(in
.readLine());
41 int n
= Integer
.parseInt(st
.nextToken());
42 int m
= Integer
.parseInt(st
.nextToken());
43 checkBounds(n
, 1, 10000, "n");
44 checkBounds(m
, 1, 10, "m");
45 int[][] t
= new int[n
][m
];
46 Map
<String
, Integer
> words
= new HashMap
<String
, Integer
>();
48 for (int i
= 0; i
< n
; i
++) {
49 String line
= in
.readLine();
50 check(line
.length() <= 80, "line too long");
51 st
= new StringTokenizer(line
, ",");
52 for (int j
= 0; j
< m
; j
++) {
53 String word
= st
.nextToken();
54 for (int u
= 0; u
< word
.length(); u
++) {
55 char ch
= word
.charAt(u
);
56 check((' ' <= ch
) && (ch
<= '~'), "invalid symbol in word: " + ch
);
58 check(word
.charAt(0) != ' ', "leading spaces in word");
59 check(word
.charAt(word
.length() - 1) != ' ', "trailing spaces in word");
60 if (!words
.containsKey(word
)) {
61 words
.put(word
, wordsCount
++);
63 t
[i
][j
] = words
.get(word
);
66 Row
[] rows
= new Row
[n
];
67 for (int i
= 0; i
< n
; i
++) {
70 for (int u
= 0; u
< m
; u
++) {
71 for (int v
= u
+ 1; v
< m
; v
++) {
72 for (int i
= 0; i
< n
; i
++) {
78 for (int i
= 0; i
< n
- 1; i
++) {
79 if (rows
[i
].u
== rows
[i
+ 1].u
&& rows
[i
].v
== rows
[i
+ 1].v
) {
81 out
.println(rows
[i
].num
+ " " + rows
[i
+ 1].num
);
82 out
.println((u
+ 1) + " " + (v
+ 1));
91 public static void main(String
[] args
) {
92 new Thread(new database_rs()).start();
96 String problem
= getClass().getName().split("_")[0];
98 in
= new BufferedReader(new FileReader(new File(problem
+ ".in")));
99 out
= new PrintWriter(new File(problem
+ ".out"));
103 } catch (IOException e
) {