Could you help with the task? He wrote his decision, but it is not true. Here is the challenge.
Input data
The first line contains the number N (1 <= N <= 100000) --- the number of segments. Further, the segments themselves are given in pairs of integers, the left and the right end. The coordinates of the ends lie in the range from 1 to 10 ^ 9.
Output
Print the number of segments in the desired set. Then output the segment in ascending order of the left end.
Example
Enter 3 10 12 1 5 3 7
Conclusion 2 3 7 10 12
Here is my decision. Yo it does not work. I cannot understand why the answer is 3 7 and 10 12, and not 2 (3 7) (10 12) and (1 5) (10 12).
#include "stdafx.h" #include <iostream> #include <windows.h> int n; int xy[100000][2]; int sum[100000][2]; int sum1[100000][2]; int nam; using namespace std; int main() { int j; nam = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> xy[i][1] >> xy[i][2]; } for (j = 0; j < n; j++) { for (int b = j; b < n; b++) { if ((xy[j][1] < xy[b][1]) && (xy[j][2] < xy[b][1]) || xy[j][1] > xy[b][2]) { sum[j][1] = xy[j][1]; sum[j][2] = xy[j][2]; sum1[j][1] = xy[b][1]; sum1[j][2] = xy[b][2]; nam++; cout << sum[j][1] << " " << sum[j][2] << " " << endl << sum1[j][1] << " " << sum1[j][2] << endl; } } } cout << nam; }
Show plz on the example of code 2 day I can not write :(