codeforces A. Difference Row

October 7, 2013
CodeForces

link: http://codeforces.com/contest/347/problem/A

开始看起来很复杂的样子,但是刚写下样例,就发现因为中间的都消去了,其实起作用的就是最大值和最小值=_=

#include <cstdio>
#include <algorithm>
using namespace std;
int a[102];
int main(void) 
{
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
#endif
    int n;
    while (~scanf("%d", &n))
    {
        int i;
        for (i = 0; i < n; scanf("%d", a+i++));
        sort(a, a+n);
        printf("%d", a[n-1]);
        for (i = 1; i < n-1; ++i)
            printf(" %d", a[i]);
        printf(" %d\n", a[0]);
    }
    return 0;
}

排序后输出就行。

comments powered by Disqus