再求助一次,求大佬解答..
查看原帖
再求助一次,求大佬解答..
522135
山迟暮楼主2021/7/26 12:47

感觉逻辑没问题,但是输出不来。

#include<bits/stdc++.h>
using namespace std;

int tmp[1005],a[1005];

void paixu(int begin,int end,int mid){
	int i,u,p;
	i = begin;u = begin;p = mid; 
	while(i<mid&&p<=end){
		if(a[i]<a[p]) tmp[u++] = a[i++];
		else tmp[u++] = a[p++];
	}
	while(i<mid)tmp[u++] = a[i++];
	while(p<=end)tmp[u++] = a[p++];
	i = begin; p = begin;
	while(i<=end) a[i++] = tmp[p++]; 
}

void anssort(int begin,int end){
	int mid;mid = (begin+end)/2;
	if(mid<1)return;
	anssort(begin,mid);
	anssort(mid+1,end);
	paixu(begin,end,mid+1);
}

int main(){
	int n,k;
	cin >> n >> k;
	for(int i = 0; i < n; i++) cout<<a[i];
	anssort(a[0],a[n-1]);
	cout<<a[k];
	return 0;
}
2021/7/26 12:47
加载中...