-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTask_56.java
72 lines (64 loc) · 2.35 KB
/
Task_56.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
package Task_acmp;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
public class Task_56 {
public static void main(String[] args) throws Exception {
BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
int quantityFriend = Integer.parseInt(rd.readLine());
ArrayList<String> friends = new ArrayList<>(quantityFriend);
ArrayList<String> mutualFriends = new ArrayList<>();
ArrayList<String> alsoFriend = new ArrayList<>();
for (int i = 0; i < quantityFriend; i++) {
friends.add(rd.readLine());
}
int quantityMutualFriends = Integer.parseInt(rd.readLine());
boolean present;
for (int i = 0; i < quantityMutualFriends; i++) {
String mutualQuality = rd.readLine();
present = false;
for (int j = 0; j < quantityFriend; j++) {
String friend = friends.get(j);
present = friend.equals(mutualQuality);
if (present) {
mutualFriends.add(mutualQuality);
break;
}
}
if (!present) {
alsoFriend.add(mutualQuality);
}
}
rd.close();
Collections.sort(friends);
Collections.sort(mutualFriends);
Collections.sort(alsoFriend);
System.out.print("Friends: ");
for (int i = 0; i < friends.size(); i++) {
if (i < friends.size() - 1)
System.out.print(friends.get(i) + "," + " ");
else {
System.out.print(friends.get(i));
}
}
System.out.println();
System.out.print("Mutual Friends: ");
for (int i = 0; i < mutualFriends.size(); i++) {
if (i < mutualFriends.size() - 1)
System.out.print(mutualFriends.get(i) + "," + " ");
else {
System.out.print(mutualFriends.get(i));
}
}
System.out.println();
System.out.print("Also Friend of: ");
for (int i = 0; i < alsoFriend.size(); i++) {
if (i < alsoFriend.size() - 1)
System.out.print(alsoFriend.get(i) + "," + " ");
else {
System.out.print(alsoFriend.get(i));
}
}
}
}