Topic 1185: Special sort

Source: Internet
Author: User

Title Description:

Enter a series of integers, pick the largest number out, and sort the remaining numbers.

Input:
Enter the first line to include 1 integer n,1<=n<=1000, which represents the number of input data. The next line has n integers.
Output:
there may be more than one set 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
Tips:

If there is only one number in the array, when the first row has its output, the second line outputs "1".



#include <stdio.h> #include <algorithm> using namespace std;            int main () {int n;            int buf[1000];                            while (scanf ("%d", &n)! = EOF) {for (int i=0; i<n; i++) {                    scanf ("%d", &buf[i]);                    } sort (buf, buf+n);                            if (n==1) {printf ("%d\n", buf[0]);                    printf (" -1\n");                            } else {printf ("%d\n", buf[n-1]);                            for (int i=0; i<n-2; i++) {printf ("%d", buf[i]);                    } printf ("%d\n", Buf[n-2]);    }} return 0; }/************************************************************** problem:1185 User:carvin language:c++ result:accepted time:30 Ms memory:1020 kb****************************** **********************************/



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Topic 1185: Special sort

Related Article

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.