1185 Special Sort

Source: Internet
Author: User

/* Use the quick line to implement the title description: Enter a series of integers, pick out the largest number, and sort the remaining numbers. Input: Enter the first line including 1 integer n,1<=n<=1000, which represents the number of input data. The next line has n integers. Output: There may be multiple sets of test data, for each set of data, the first line outputs an integer representing the maximum value in n integers, and the value is removed from the array, and the remaining number is sorted. The second row will sort the result output. Sample input: 41 3 4 2 sample output: 41 2 3 Tip: If there is only one number in the array, when the first row has its output, the second line outputs "-1".  */# include <stdio.h>void QuickSort (int * A, int low, int.) {int left,right,pivot;pivot = A[low];left = Low;right = High;while (Low < High) {when (Low < high && A[high] >= pivot) High--;a[low] = A[high];while (Low < HIG H && A[low] <= pivot) Low++;a[high] = A[low];} A[low] = Pivot;if (left! = Low) QuickSort (A, left, low-1); "Right! = High" QuickSort (A, low+1, right);}    int main (void) {int n;while (scanf ("%d", &n)! = EOF) {GetChar (); Absorbs the carriage return character. int i,a[1010];for (i = 0; i < n; i++) {scanf ("%d", &a[i]);} if (n = = 1) {printf (" -1\n"); continue;} Else{quicksort (A, 0, n-1);p rintf ("%d\n", a[n-1]), for (i = 0; i < n-1; i++) {printf ("%d", A[i]);} printf ("\ n");}} return 0;}

1185 Special Sort

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.