-
Notifications
You must be signed in to change notification settings - Fork 0
/
Friends_ages.cpp
46 lines (35 loc) · 1014 Bytes
/
Friends_ages.cpp
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
#include<bits/stdc++.h>
#include<map>
using namespace std;
void friends(int arr[], int n) {
int i = 0, j = 0;
int count = 0;
map<int, vector<int>> mp;
for (i = 0; i < n; i++) {
for (j = i+1; j < n; j++) {
if ((arr[j] <= 0.5 * arr[i] + 7) || (arr[j] > 100 && arr[i] < 100) || (arr[j] > arr[i])) {
continue ;
} else if ((find(mp[arr[i]].begin(), mp[arr[i]].end(), arr[j]) != mp[arr[i]].end()) ||
(find(mp[arr[j]].begin(), mp[arr[j]].end(), arr[i]) != mp[arr[j]].end())) {
continue;
} else {
mp[arr[i]].push_back(arr[j]);
mp[arr[j]].push_back(arr[i]);
cout << arr[i] << " " << arr[j] << endl ;
count++;
}
}
}
cout << count << endl;
}
int main() {
int n;
cin >> n;
int arr[n];
int i = 0;
for (i = 0; i < n; i++) {
cin >> arr[i];
}
friends(arr, n);
return 0;
}