Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
134527 | 林泽豪 | 常用排序法 | C++ | 通过 | 100 | 26 MS | 636 KB | 616 | 2024-03-02 16:09:03 |
#include<bits/stdc++.h> using namespace std; int a[100003]; int n; void selectsort(){ for(int i=1;i<n;i++){ int as=i; for(int j=i+1;j<=n;j++){ if(a[as]>a[j])as=j; } swap(a[i],a[as]); } } void qsort(int l,int r){ int i=l,j=r,mid; mid=a[(l+r)/2]; do{ while(a[i]<mid)i++; while(a[j]>mid)j--; if(i<=j){ swap(a[i],a[j]); i++;j--; } }while(i<=j); if(l<j)qsort(l,j); if(i<r)qsort(i,r); } int main(){ cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; } qsort(1,n); for(int i=1;i<=n;i++){ cout<<a[i]<<' '; } }