-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path12.cpp
More file actions
58 lines (54 loc) · 1.24 KB
/
12.cpp
File metadata and controls
58 lines (54 loc) · 1.24 KB
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
#include <iostream>
using namespace std;
int main()
{
int n,m,a,b;
cout << "enter n" << endl;
cin >>n;
int **mas=new int*[n];
for (int i=0;i<n;i++){
mas[i]=new int[2];
a=rand()%100;
b=rand()%100;
if (a>b){
mas[i][0]=b;
mas[i][1]=a;
}
else{
mas[i][1]=b;
mas[i][0]=a;
}
}
for (int i=0;i<n;i++) {
for (int j=0;j<n-i-1;j++) {
if (mas[j][1]>mas[j+1][1]) {
swap(mas[j],mas[j+1]);
}
}
}
for (int i=0;i<n;i++){
//cout <<mas[i][0]<<" "<<mas[i][1]<<endl;
}
for (int i=0;i<n;i++) {
for (int j=0;j<n;j++) {
if ((mas[i][0]>mas[j][0]) && (mas[i][1]<mas[j][1])) {
mas[j][0]=-1;
mas[j][1]=-1;
}
}
}
cout <<endl;
for (int i=0;i<n;i++){
//cout <<mas[i][0]<<" "<<mas[i][1]<<endl;
if ((mas[i][0]!=-1) && (m==0))
m=mas[i][1];
}
int s=1;
for (int i=0;i<n;i++){
if ((mas[i][0]!=-1) && (mas[i][0]>m)){
s++;
m=mas[i][1];
}
}
cout <<s<<endl;
}