4 条题解
-
0
写了个最麻烦的
#include<stdio.h> #include<string.h> void swap(int *a, int *b) { int temp = *a; *a = *b; *b = temp; } void quick_sort(int tot[],int l,int r) { if(l>=r){ return; } int q=tot[l]; int i=l-1,j=r+1; while(i<j){ do i++;while(tot[i]<q); do j--;while(tot[j]>q); if(i<j) swap(&tot[i],&tot[j]); } quick_sort(tot,l,j); quick_sort(tot,j+1,r); } int main(){ int n; scanf("%d",&n); int tot[1000]; int i; for(i=0;i<n;i++){ scanf("%d",&tot[i]); } quick_sort(tot,0,n-1); for(i=0;i<n;i++){ printf("%d ",tot[i]); } return 0; } -
0
可以用自带的快排函数,qsort或者sort,也可以冒泡等方法,最后输出就好。
#include<stdio.h> #include<stdlib.h> #include<math.h> int cmp(const void*a,const void*b){ return(*(int*)a-*(int*)b); } int main(){ int i,n;scanf("%d",&n); int a[n]; for(i=0;i<n;i++){ scanf("%d",&a[i]); } qsort(a,n,sizeof(int),cmp); for(i=0;i<n;i++){ printf("%d ",a[i]); } return 0; }
- 1
信息
- ID
- 247
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 4
- 标签
- 递交数
- 409
- 已通过
- 191
- 上传者