-
Notifications
You must be signed in to change notification settings - Fork 0
/
MatchMaker.java
82 lines (77 loc) · 2.95 KB
/
MatchMaker.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import java.util.*;
import java.io.*;
public class MatchMaker {
public static Set<Marriage> generator(Set<Man> men, Set<Woman> women) {
Set<Marriage> ans = new ArraySet<Marriage>();
for (int i = 0; i < women.size(); i++) {
Iterator itr = men.iterator();
while (itr.hasNext()) {
Man temp = ((Man) itr.next());
for (int r = 0; r <= i; r++) {
if (temp.equals(temp.getWoman(i).getMan(r))) {
ans.add(new Marriage(temp, temp.getWoman(r)));
}
}
}
}
return ans;
}
public static Woman getWoman(String name, ArrayList<Woman> women){
for (int i = 0; i < women.size(); i++){
if (name.equals(women.get(i).getName()))
return women.get(i);
}
System.out.println("error");
return null;
}
public static Man getMan(String name, ArrayList<Man> men){
for (int i = 0; i < men.size(); i++){
if (name.equals(men.get(i).getName()))
return men.get(i);
}
System.out.println("error");
return null;
}
public static void main(String[] args) throws IOException {
BufferedReader f = new BufferedReader(new FileReader("data.txt"));
ArrayList<Man> men = new ArrayList<Man>();
ArrayList<Woman> women = new ArrayList<Woman>();
int num_people = Integer.parseInt(f.readLine());
StringTokenizer get_men = new StringTokenizer(f.readLine());
StringTokenizer get_women = new StringTokenizer(f.readLine());
while (get_men.hasMoreTokens()){
men.add(new Man(get_men.nextToken()));
}
while (get_women.hasMoreTokens()){
women.add(new Woman(get_women.nextToken()));
}
for (int i = 0; i < men.size(); i++){
Man my_man = getMan(f.readLine(), men);
ArrayList<Woman> pref = new ArrayList<Woman>();
StringTokenizer st = new StringTokenizer(f.readLine());
for (int q = 0; q < women.size(); q++){
pref.add(getWoman(st.nextToken(), women));
}
my_man.setPartners(pref);
}
for (int i = 0; i < men.size(); i++){
Woman my_woman = getWoman(f.readLine(), women);
ArrayList<Man> pref = new ArrayList<Man>();
StringTokenizer st = new StringTokenizer(f.readLine());
for (int q = 0; q < men.size(); q++){
pref.add(getMan(st.nextToken(), men));
}
my_woman.setPartners(pref);
}
ArraySet<Man> menset = new ArraySet<Man>();
ArraySet<Woman> womenset = new ArraySet<Woman>();
for (int i = 0; i < men.size(); i++){
menset.add(men.get(i));
womenset.add(women.get(i));
}
Iterator itr = generator(menset, womenset).iterator();
while (itr.hasNext()){
System.out.println(itr.next());
}
}
}