-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasicprogramming2.cpp
More file actions
73 lines (70 loc) · 1.62 KB
/
basicprogramming2.cpp
File metadata and controls
73 lines (70 loc) · 1.62 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
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define ar array
#define ll long long
int main() {
int n,t;
cin>>n>>t;
int arr[n];
for(int i=0;i<n;i++) cin>>arr[i];
if(t==1){
bool yes=false;
sort(arr, arr+n);
int i=0,j=n-1;
while(i<j){
int x=arr[i],y=arr[j];
if(x==y) break;
if(x+y==7777) {
yes=true; break;
}else if(x+y>7777){
j--;
}else{
i++;
}
}
cout<<(yes?"Yes":"No");
}else if(t==2){
unordered_set<int> present;
bool dup=false;
for(int e:arr){
if(present.find(e)!=present.end()){
dup=true; break;
}else{
present.insert(e);
}
}
cout<<(dup?"Contains duplicate":"Unique");
}else if(t==3){
unordered_map<int,int> freq;
for(int e:arr){
freq[e]++;
}
bool found=false;
for(auto i:freq){
if(i.second>n/2){
cout<<i.first; found=true; break;
}
}
if(!found) cout<<"-1";
}else if(t==4){
sort(arr, arr+n);
if(n%2==0){
cout<<arr[n/2-1]<<" "<<arr[n/2];
}else{
cout<<arr[n/2];
}
}else if(t==5){
sort(arr, arr+n);
bool first=true;
for(int e:arr){
if(e>=100&&e<=999){
if(!first) cout<<" ";
else first=false;
cout<<e;
}
}
}
cout<<endl;
}