Advertisement
rotti321

intervale crescatoare

Jan 3rd, 2022
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. /// se dau n intervale de forma [A,B],
  2. ///afisati aceste intervale crescator dupa A
  3. ///si apoi dupa B
  4. #include <bits/stdc++.h>
  5.  
  6. using namespace std;
  7. struct interval
  8. {
  9. int a,b;
  10. }v[101];
  11. bool cmp(interval p,interval q)
  12. {
  13. if(p.a<q.a) return 1;
  14. if(p.a==q.a) return (p.b<q.b);
  15. if(p.a>q.a) return 0;
  16. }
  17. int main()
  18. {
  19. int n;
  20. cin>>n;
  21. for(int i=1;i<=n;i++)
  22. {
  23. cin>>v[i].a>>v[i].b;
  24. }
  25. sort(v+1,v+n+1,cmp);
  26. for(int i=1;i<=n;i++)
  27. {
  28. cout<<v[i].a<<" "<<v[i].b<<endl;
  29.  
  30. }
  31. return 0;
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement