백준 1931 c++
#include <iostream>
#include <vector>
#include <algorithm>
#include <limits.h>
using namespace std;
int input(int lower, int upper)
{
//cout << "input()" << endl;
int A;
while (1)
{
cin >> A;
if (A >= lower && A <= upper)
{
break;
}
else
{
;
}
}
return A;
}
//void input_arr(int** A, int N)
void input_arr(vector <pair<int, int>> &A, int N)
{
//cout << "input_arr()\n";
int i;
int temp1, temp2;
for (i = 0; i < N; i++)
{
//A[i][0] = input(0, 2147483647);
//A[i][1] = input(0, 2147483647);
temp1 = input(0, INT_MAX);//begin
temp2 = input(0, INT_MAX);//end
A.push_back(make_pair(temp2, temp1));
}
return;
}
int find_result(vector <pair<int, int>> A, int N)
{
//cout << "find_result()\n";
int i, count = 1;
int temp;
/*for (i = 0; i < N; i++)
{
cout << A[i].first << " " << A[i].second << "\n";
}*/
temp = A[0].first;
for (i = 1; i < N; i++)
{
if (temp <= A[i].second)
{
temp = A[i].first;
count++;
}
else
{
;
}
}
return count;
}
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N; /*, i;*/
//int **timeTable;
vector <pair<int, int>> timeTable;
N = input(1, 100000);
/*timeTable = new int* [N];
for (i = 0; i < N; i++)
{
timeTable[i] = new int[2];
}*/
input_arr(timeTable, N);
sort(timeTable.begin(), timeTable.end()
/*,
[](const std::pair<int, int>& a, const std::pair<int, int>& b)
{
return a.second < b.second;
}*/
);//second 기준 오름차순 정렬
cout << find_result(timeTable, N) << "\n";
/*for (i = 0; i < N; i++)
{
delete[] timeTable[i];
}
delete[] timeTable;*/
return 0;
}