求问大佬们这个代码为啥前三个测试都是WA
查看原帖
求问大佬们这个代码为啥前三个测试都是WA
615345
LJHgo楼主2022/3/8 15:44
#include<iostream>
#include<bits/stdc++.h>
using namespace std;

void sortpro(vector<int>& nums, int start, int end) {
   if (start >= end)return;
   int L = start, R = end;
   int val = L + ((R - L) >> 1);
   while (L <= R) {
   	while (L <= R && nums[L] < nums[val]) {
   		L++;
   	}
   	while (L <= R && nums[R] > nums[val]) {
   		R--;
   	}
   	if (L <= R)
   	{
   		swap(nums[L],nums[R]);
   		L++; R--;
   	}
   }
   sortpro(nums, start, R);
   sortpro(nums, L, end);
}
int main()
{
   int n; cin >> n;
   vector<int>nums(n);
   for (int i = 0; i < nums.size(); i++) {
   	cin >> nums[i];
   }
   sortpro(nums, 0, nums.size() - 1);
   for (int i = 0; i < nums.size(); i++)
   	cout << nums[i] << " ";

   return 0;
}
2022/3/8 15:44
加载中...