-
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