Home > Back-end >  Turn to PAT serie b 1045 test points of 35
Turn to PAT serie b 1045 test points of 35

Time:09-30

 # include & lt; stdio.h> 
#include
#include
#include
#include

Int CMP (const void * a, const void * b) {
Int * c=(int *) a;
Int b * d=(int *);
Return * c - * d;
}

Int main () {
int n,i,j;
The scanf (" % d ", & amp; N);
Int a [n], b [n].
Int CNT=0;

for(i=0; IThe scanf (" % d ", & amp; A [I]);
B=[I] a [I];

}
Tree (b, n, sizeof (int), CMP);
Int c [n].
for(i=0; IIf (a [0]==b [0]) {
If ([I] a [I]==b) {
C=[cnt++] a [I];
}
} else {
break;
}
}
Printf (" % d \ n ", CNT);
for(i=0; Iif(i! CNT=1) {
Printf (" % d ", [I] c);
} else {
Printf (" % d ", [I] c);
}

}
printf("\n");
return 0;

}

CodePudding user response:

Topic request the following
Famous quick sort algorithm in the division of a classic process: we usually use some way to get an element as the main yuan, through the exchange, the element that is smaller than principal component on the left side of it, than the right side of the main yuanta elements in it, the given segments of the arrangement of N positive integers each other is not the same, do you have how many elements may be selected before the main divided into RMB?

A given $N=5 $, for example, is 1,3,2,4,5, is:

1 left no elements, the right of the element is bigger than it, so it may be the main yuan;
Although the left side of the three elements are smaller than it, but the 2 smaller than it in the right hand, so it can't be a principal;
Although 2 on the right side of the element is bigger than it, but its on the left side of the 3 than it, so it can't be a principal;
Similar reasons, 4 and 5 is likely to be the main yuan,
As a result, there are three elements may be the main yuan,

Input format:
Input in line 1 is given a positive integer N (10 or less
? 5
?? ); Line 2 is a space-delimited N different positive integers, each not more than 10
? 9
?? ,

The output format:
In line 1 output is likely to be the number of elements in the principal; In line 2, the output of these elements in increasing order, meanwhile to a space-delimited, fore and aft may not have surplus space,

Input the sample:
5
1 2 3 4 5



The output sample:
3
1, 4, 5

CodePudding user response:

Don't think for a long time to understand

CodePudding user response:

The building Lord you don't understand ah, I can't test point 3 and 5 also through, don't know where is wrong,,,

CodePudding user response:

reference Wxy_2018 reply: 3/f
the building Lord you don't understand ah, I can't test point 3 and 5 also through, don't know where is wrong,,,
passed, did you think that might be it just among a certain number is the same with sorted but the number is not the main yuan

CodePudding user response:

939493 reference 4 floor response:
Quote: refer to the third floor Wxy_2018 response:
the building Lord you don't understand ah, I can't test point 3 and 5 also through, don't know where is wrong,,,
passed, did you think that may be it just among a certain number is the same with sorted but that number is not the main yuan
ok, I try, lz, ~
  • Related