-
Notifications
You must be signed in to change notification settings - Fork 0
/
games.java
42 lines (30 loc) · 888 Bytes
/
games.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
import java.util.*;
public class JavaProgram {
public static void main(String[] args) {
// System.in and System.out are input and output streams, respectively.
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int count = 0;
int[][] arr = new int[n][2];
for (int i = 0; i<n; i++){
for (int j = 0; j<2; j++){
arr[i][j] = sc.nextInt();
}
}
for (int i = 0; i<n-1; i++){
for (int j = i+1; j<n;j++){
if (arr[i][0] == arr[j][1]){
count++;
}
}
}
for (int i = 0; i<n-1; i++){
for (int j = i+1; j<n;j++){
if (arr[i][1] == arr[j][0]){
count++;
}
}
}
System.out.println(count);
}
}