80pts求调
查看原帖
80pts求调
1117573
ylswznzs楼主2024/5/1 20:30
#include <iostream>
#include <algorithm>
using namespace std;
long w[1000010];
bool cmp(int x,int y)
{
    return x>y;
}
int main()
{
    long n;
    cin>>n;
    for (int i=0;i<n;i++)cin>>w[i];
    sort(w,w+n);
    long tmp=w[n-2];
    w[n-2]=w[0],w[0]=tmp;
    for (int i=0;i<n;i++)cout<<w[i]<<' ';
    cout<<endl;
    sort(w,w+n,cmp);
    tmp=w[n-2];
    w[n-2]=w[0],w[0]=tmp;
    for (int i=0;i<n;i++)cout<<w[i]<<' ';
    return 0;
}

个人思路就是把最大次大放在头尾,最小时相反

2024/5/1 20:30
加载中...