-
Notifications
You must be signed in to change notification settings - Fork 0
/
basicprogramming2.cpp
119 lines (110 loc) · 1.97 KB
/
basicprogramming2.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
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
108
109
110
111
112
113
114
115
116
117
118
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define FOR(i,a,b) for(int i = a;i<b;i++)
#define INF (unsigned)!((int)0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
const int NIL = -1;
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
int main () {
ios_base::sync_with_stdio(0);cin.tie(0);
int n , t; cin>>n>>t;
if(t == 1){
std::vector<int> v;
for (int i = 0; i < n; ++i)
{
int x; cin>>x;
v.pb(x);
}
v.erase( unique( v.begin(), v.end() ), v.end() );
int l = 0 , r = v.size() - 1;
sort(v.begin(), v.end());
for(int i =0 ;i<v.size();i++){
if(v[l] + v[r] < 7777){
l++;
}else if(v[l] + v[r] > 7777){
r--;
}else{
cout<<"Yes";
return 0 ;
}
}
cout<<"No";
}else if(t == 2){
set<int> se;
for (int i = 0; i < n; ++i)
{
int x; cin>>x;
se.insert(x);
}
if(se.size() == n){
cout<<"Unique";
}else{
cout<<"Contains duplicate";
}
}else if( t == 3){
int r = n / 2;
int a[n];
for (int i = 0; i < n; ++i)
{
cin>>a[i];
}
sort(a, a +n);
int ans = 1;
for (int i = 0; i < n-1; ++i)
{
if(a[i] == a[i+1]){
ans++;
if(ans > r){
cout<<a[i];
return 0 ;
}
}else{
ans = 1;
}
}
cout<<-1;
}else if( t== 4){
int a[n];
for (int i = 0; i < n; ++i)
{
cin>>a[i];
}
sort(a, a + n);
if(n % 2 == 0){
cout<<a[n/2 - 1]<<" "<<a[n/2];
return 0 ;
}else{
cout<<a[n/2];
return 0 ;
}
}else if(t == 5){
vector<int> v;
for (int i = 0; i < n; ++i)
{
int x; cin>>x;
if( x >= 100 && x <= 999){
v.pb(x);
}
}
sort(v.begin(), v.end());
for(int x : v){
cout<<x<<" ";
}
}
return 0 ;
}