sdut oj 2109 to find a girlfriend

sdut oj 2109 to find a girlfriend
la la la white for the first time to write a blog to write a simple and quick direct sequencing row set by set may be some wrong with Kazakhstan, to welcome you all to come to big-old pointing ~

Add a link description
fast row ~

#include <iostream>
int a[1000005],n;
using namespace std;
void quicksort(int left,int right){
    int temp=a[left];
    int i=left,j=right;
    if(i>j) return;
    while(i!=j){
        while(a[j]>=temp&&i<j) j--;
        while(a[i]<=temp&&i<j) i++;
        if(i<j){
            int t=a[j];
            a[j]=a[i];
            a[i]=t;
}
a[left]=a[i];
a[i]=temp;

quicksort(left,i-1);
quicksort(i+1,right);
}
}
int main()
{
cin>>n;
for(int i=0;i<n;i++){
    cin>>a[i];
}
quicksort(0,n-1);

for(int i=n-1;i>=0;i++){
    if(i==n-1){
cout<<a[i]<<endl;
break;
}
cout<<a[i]<<" ";
}
return 0;
}

set Collection

#include <iostream>
#include <set>

using namespace std;

int main(){
std::multiset<int> se;
int n;
int x;

cin>>n;
while(n--){
    scanf("%d",&x);
    se.insert(x);
}
//printf("%d\n",se.count(3));
//printf("%d\n",se.size());
//printf("%d\n",*se.lower_bound(3));
//printf("%d\n",*se.upper_bound(3));
//printf("%d\n",*se.find(3));
    std::set<int>::iterator it=se.end();//开
    it--;//set集左闭右开
    while(it!=se.begin()){
        printf("%d "*it);
        it--;
}
printf("%d\n",*it);
return 0;
}
Released four original articles · won praise 1 · views 63

Guess you like

Origin blog.csdn.net/weixin_45186911/article/details/103955435