HDU2673: sh orororz

Source: Internet
Author: User

Problem DescriptionAcmer in HDU-ACM team are ambitious, especially sh, he can spend time in Internet bar doing problems overnight. so far girls want to meet and Orz him. but Orz him is not that easy. you must solve this problem first. the problem is: Give you a sequence of distinct integers, choose numbers as following: first choose the biggest, then smallest, then second biggest, second smallest etc. until all the numbers was chosen. for example, give you 1 2 3 4 5, you showould output 5 1 4 2 3 InputThere are multiple test cases, each case begins with one integer N (1 <= N <= 10000), following N distinct integers. outputOutput a sequence of distinct integers described above. sample Input51 2 3 4 5 Sample Output5 1 4 2 3 Fast-forward application [cpp] # include <iostream> # include <cstdio> # include <cstring> # include <algorithm> using namespace std; int cmp (const void * a, const void * B) {return (* (int *) a-* (int *) B);} int main () {int n, i, num [10005], a [10005]; while (cin> n) {int flag, flag2; flag = n/2; flag2 = n-flag; memset (a, 0, sizeof (a); memset (num, 0, sizeof (num); for (I = 0; I <n; I ++) cin> num [I]; qsort (num, n, sizeof (int), cmp); int k = 0; for (I = n-1; flag2 --; I --) {a [k] = num [I]; k + = 2;} k = 1; for (I = 0; flag --; I ++) {a [k] = num [I]; k + = 2;} cout <a [0]; for (I = 1; I <n; I ++) {cout <"" <a [I];} cout <endl;} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.