topic
There are number N, of the first array to the second number in ascending order of the sort. Then the first array to the second digital sorted in descending order.
Input Format
The first input line of five integers , , , , , where 0 < < < , 0 < < < , five numbers are not more than 10,000;
The second behavior N integers.
Output Format
N integers line, shows the result after sorting array, separated by spaces between the numbers, the end of the wrapping.
Code
#include<bits/stdc++.h>
using namespace std;
int arr[10010];
bool judge_1(int a, int b){
return a > b;
}
int main(){
int N, l1, r1, l2, r2;
cin >> N >> l1 >> r1 >> l2 >> r2;
for(int i = 0; i < N; i++){
cin >> arr[i];
}
sort(arr + l1 - 1, arr + r1);
sort(arr + l2 - 1, arr + r2, judge_1);
for(int i = 0; i < N; i++){
cout << arr[i];
if(i != N - 1)
cout << " ";
}
return 0;
}
This topic has a relatively small error-prone points, using the sort () to sort, we should pay attention to the function parameters:
- The first is to sort the starting address of the array.
- The second is the end of the address (the last one to sort of address)
- The third parameter is the sort of method, but also can be big to small from small to large, you can not write the third parameter, then the default is to sort in ascending order.
Accordingly Here, the start address of the first number K for the ARR K + -. 1 .