Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <fstream>
  4. using namespace std;
  5. ifstream fin("spectacole.in");
  6. ofstream fout("spectacole.out");
  7. int n, s = 0;
  8. struct Spectacol
  9. {
  10. int inceput, sfarsit;
  11.  
  12. /*istream& operator>>(istream& in, Spectacol& out) {
  13. in >> out.inceput >> out.sfarsit;
  14. return in;
  15. }*/
  16. }spectacole[128];
  17.  
  18. void citire() {
  19. fin>>n;
  20. for (int i = 0; i < n; ++i)
  21. {
  22. fin>>spectacole[i].inceput>>spectacole[i].sfarsit;
  23. }
  24. }
  25.  
  26. void this_is_your_job_bejan() {
  27. Spectacol prev = spectacole[0];
  28. int i = 1;
  29. //cout << "\n\t\tstart\n";
  30. while (i < n) {
  31. if(prev.sfarsit <= spectacole[i].inceput)
  32. {
  33. //cout << prev.inceput << ' ' << prev.sfarsit << endl;
  34. ++s;
  35. prev = spectacole[i];
  36.  
  37. }
  38. ++i;
  39. }
  40. //cout << prev.inceput << ' ' << prev.sfarsit << endl;
  41. //cout << "\n\t\tend\n";
  42. }
  43.  
  44. int main()
  45. {
  46. citire();
  47. /*for (int i = 0; i < n; i++) {
  48. cout << spectacole[i].inceput<< ' ' << spectacole[i].sfarsit << endl;
  49. }cout<<"\n\n";*/
  50. std::sort(spectacole, spectacole + n, [](const Spectacol& a, const Spectacol& b) -> bool {
  51. return a.inceput < b.inceput && a.sfarsit < b.sfarsit;
  52. });
  53. /*for (int i = 0; i < n; i++) {
  54. cout << spectacole[i].inceput<< ' ' << spectacole[i].sfarsit << endl;
  55. }*/
  56. this_is_your_job_bejan();
  57.  
  58. fout << s + 1;
  59.  
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement