Advertisement
Diene

Untitled

Dec 24th, 2018
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. struct com{
  6.     int ini, fin;
  7. };
  8.  
  9. bool compara(com a, com b){
  10.     return a.fin<b.fin;
  11. }
  12.  
  13. com consulta[1004];
  14.  
  15. int n, livre, qtd;
  16.  
  17. int main(){
  18.  
  19.     cin >> n;
  20.     for(int i=1;i<=n;i++){
  21.         cin >> consulta[i].ini >> consulta[i].fin;
  22.     }
  23.     sort(consulta+1,consulta+n+1, compara);
  24.     for(int i=1;i<=n;i++){
  25.         if(consulta[i].ini>=livre){
  26.             qtd++;
  27.             livre=consulta[i].fin;
  28.         }
  29.     }
  30.     cout << qtd << "\n";
  31.     return 0;
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement