题目描述
https://www.acwing.com/problem/content/789/
C++ 代码
include[HTML_REMOVED]
include[HTML_REMOVED]
using namespace std;
int q[1000010],tmp[1000010],n;
void msort(int q[],int l,int r)
{
if(l>=r) return;
int mid=(l+r)>>1;
msort(q,l,mid);
msort(q,mid+1,r);
int k=1,i=l,j=mid+1;
while(i<=mid&&j<=r)
if(q[i]<=q[j]) tmp[k]=q[i];
else tmp[k]=q[j];
while(i<=mid) tmp[k]=q[i];
while(j<=r) tmp[k]=q[j];
for(i=l,j=1;i<=r;i,j)
q[i]=tmp[j];
}
int main()
{
scanf(“%d”,&n);
for(int i=1;i<=n;i)
scanf(“%d”,&q[i]);
msort(q,1,n);
for(int i=1;i<=n;i)
printf(“%d “,q[i]);
return 0;
}
在贴代码的时候呢,建议在代码首尾加分别上一组
$\text{```}$
这样才能正确显示代码高亮哦~