请大家帮忙看看~~
查看原帖
请大家帮忙看看~~
91975
GVNDN楼主2020/6/11 19:05

为啥前三个点WA,第一个点55350排在4048105和4695482之后输出,奇怪!

#include<iostream>
using namespace std;
int a[1000010];
void qsort(int a[], int l, int r){
	int i = l, j = r, mid = a[(l + r) / 2];
	do{
		while(a[i] < mid) i++;
		while(a[j] > mid) j--;
		if(i <= j){
			int t;
			t = a[i];
			a[i] = a[j];
			a[j] = t;
		}
		i++; j--;
	} while(i <= j);
	if(i < r) qsort(a, i, r);
	if(j > l) qsort(a, l, j);
}

int main(){
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> a[i];
	qsort(a, 1, n);
	int f = 1;
	for(int i = 1; i <= n; i++){
		if(f) {cout << a[i]; f = 0;}
		else cout << " " << a[i];
	}
	return 0;
}

谢谢

2020/6/11 19:05
加载中...