-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
107 lines (90 loc) · 1.82 KB
/
main.cpp
File metadata and controls
107 lines (90 loc) · 1.82 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
string t1(int n){
int num, diff;
unordered_set<int> nums;
for (int i = 0; i < n; i++){
cin >> num;
diff = 7777 - num;
if (nums.count(diff) && num != diff){
return "Yes";
}
nums.insert(num);
}
return "No";
}
string t2(int n){
int num;
unordered_set<int> nums;
for (int i = 0; i < n; i++){
cin >> num;
if (nums.count(num)){
return "Contains duplicate";
}
nums.insert(num);
}
return "Unique";
}
int t3(int n){
int num;
unordered_map<int, int> numCounts;
for (int i = 0; i < n; i++){
cin >> num;
numCounts[num]++;
if (numCounts[num] > n / 2) return num;
}
return -1;
}
string t4(int n){
int num;
vi a;
for (int i = 0; i < n; i++){
cin >> num;
a.push_back(num);
}
sort(a.begin(), a.end());
if (n % 2){ // odd
return to_string(a[n / 2]);
}
return to_string(a[n / 2 - 1]) + " " + to_string(a[n / 2]);
}
string t5(int n){
int num;
vi a;
for (int i = 0; i < n; i++){
cin >> num;
if (num >= 100 && num < 1000) a.push_back(num);
}
sort(a.begin(), a.end());
string output = to_string(a[0]);
for (int i = 1; i < a.size(); i++){
output += " " + to_string(a[i]);
}
return output;
}
int main(){
int n, t;
cin >> n >> t;
switch (t)
{
case 1:
cout << t1(n) << endl;
break;
case 2:
cout << t2(n) << endl;
break;
case 3:
cout << t3(n) << endl;
break;
case 4:
cout << t4(n) << endl;
break;
case 5:
cout << t5(n) << endl;
break;
default:
break;
}
return 0;
}