-
Notifications
You must be signed in to change notification settings - Fork 0
/
1045_quicksort.cpp
62 lines (60 loc) · 1.09 KB
/
1045_quicksort.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
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
long long check_left(long long *src,long long i,long long num)
{
long long flag=0;
for(long long j=0;j<i;j++)
{
if(src[j]>src[i])
{
flag++;
break;
}
}
return flag;
}
long long check_right(long long *src,long long i,long long num)
{
long long flag=0;
for(long long j=i+1;j<num;j++)
{
if(src[j]<src[i])
{
flag++;
break;
}
}
return flag;
}
int main()
{
long long num;
long long flag;
vector<long long> det;
cin>>num;
long long src[num];
for(long long i=0;i<num;i++)
{
cin>>src[i];
}
for(long long i=0;i<num;i++)
{
flag += check_left(src,i,num);
flag += check_right(src,i,num);
if(flag==0)
{
det.push_back(src[i]);
}
flag=0;
}
sort(det.begin(),det.end());
cout<<det.size()<<endl;
int i=0;
for(;i<(det.size()-1);i++)
{
cout<<det[i]<<" ";
}
cout<<det[i];
}