-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path42.c
74 lines (64 loc) · 1.6 KB
/
42.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int n, i, j;
int mas[999][3];
scanf("%d", &n);
for (i = 1; i <=n ; i+=1)
{
scanf("%d %d", &mas[i-1][0], &mas[i-1][1]);
mas[i-1][2] = 0;
}
for (i = 1; i <=n ; i+=1)
{
mas[i-1][2] = abs(mas[i-1][0] - mas[i-1][1]);
}
int k = 0;
for(i = 0 ; i < n - 1; i++)
{
for(j = 0 ; j < n - i - 1 ; j++)
{
if((mas[j][2] < mas[j+1][2]) )
{
int tmp2 = mas[j][2];
mas[j][2] = mas[j+1][2] ;
mas[j+1][2] = tmp2;
int tmp0 = mas[j][0];
mas[j][0] = mas[j+1][0] ;
mas[j+1][0] = tmp0;
int tmp1 = mas[j][1];
mas[j][1] = mas[j+1][1] ;
mas[j+1][1] = tmp1;
}
}
}
/*for (i = 0; i <=n-1 ; i+=1)
{
printf("mas :| %d %d %d |\n", mas[i][0], mas[i][1], mas[i][2]);
}*/
int itog[9999][2];
int FLAG = 0;
j = 0;
for (i = 0; i <=n-1 ; i+=1)
{
if ((mas[i][0] <= FLAG) && (mas[i][1] >= FLAG))
{
itog[j][0] = mas[i][0];
itog[j][1] = mas[i][1];
if (itog [j][1] >= 10000)
{
j ++;
break;
}
j ++;
FLAG = mas[i][1];
}
}
for (i = 0; i <=j-1 ; i+=1)
{
printf("! %d %d !\n", itog[i][0], itog[i][1]);
}
return 0;
}