forked from improper4/uva
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUVa00154_Recycling.java
49 lines (46 loc) · 1.14 KB
/
UVa00154_Recycling.java
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
package uva;
/* USER: 46724 (sfmunera) */
/* PROBLEM: 90 (154 - Recycling) */
/* SUBMISSION: 08925170 */
/* SUBMISSION TIME: 2011-06-06 22:28:04 */
/* LANGUAGE: 2 */
import java.util.*;
public class UVa00154_Recycling {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (true) {
String line = in.nextLine();
if (line.equals("#"))
break;
List<String> cities = new ArrayList<String>();
while (true) {
if (line.charAt(0) == 'e')
break;
String[] parts = line.split("[,]");
Arrays.sort(parts);
String city = "";
for (int i = 0; i < 5; ++i)
city += parts[i].charAt(2);
cities.add(city);
line = in.nextLine();
}
int min = Integer.MAX_VALUE;
int mincity = 0;
for (int i = 0; i < cities.size(); ++i) {
int cnt = 0;
for (int j = 0; j < cities.size(); ++j) {
if (i == j)
continue;
for (int k = 0; k < 5; ++k)
if (cities.get(i).charAt(k) != cities.get(j).charAt(k))
++cnt;
}
if (cnt < min) {
min = cnt;
mincity = i + 1;
}
}
System.out.println(mincity);
}
}
}