Idea: Finally, forget output wrap, I have been led to wa
Description
Give you a random sequence of integers, select the number in the following order: the biggest, the smallest, and is the second largest, second small ... until all the numbers have been elected. For example: you 13,254, you should output 51,423.
Input
A plurality of test cases, each case begins with an integer N (1 <= N <= 100000), followed by N integers below
Output
Title Description output sequence in accordance with
Sample Input
5 1 3 2 5 4
Sample Output
5 1 4 2 3
Source
#include <cstdio> #include <iostream> #include <cmath> #include <string> #include <cstring> #include <algorithm> #include <queue> #include <vector> #include <map> using namespace std; #define ll long long const int maxn = 5100; int n, a[100000+8], b[100000+8]; int main() { while(~scanf("%d", &n) && n) { for(int i = 0; i<n; i++) scanf("%d", &a[i]); sort(a, a+n, greater<int>()); int maxx = n-1, minn = 0; for(int i = 0; i<n; i++) { if(i%2 == 0) { b[i] = a[minn]; minn++; } else { b[i] = a[maxx]; maxx--; } } for(int i = 0; i<n; i++) { if(i)printf(" "); printf("%d", b[i]); } printf("\n"); } return 0; }