Guest User

Untitled

a guest
Jan 12th, 2018
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include <algorithm>
  4. #include<fstream>
  5. using namespace std;
  6.  
  7. struct activitate
  8. {
  9. int inceput,fin, profit;
  10. };
  11.  
  12. int compare(activitate a, activitate b)
  13. {
  14. if (a.fin < b.fin)
  15. return 1;
  16. return 0;
  17. }
  18.  
  19. int compareProfit(activitate a, activitate b)
  20. {
  21. if (a.profit > b.profit)
  22. return 1;
  23. return 0;
  24. }
  25.  
  26.  
  27. int main()
  28. {
  29. ifstream f("date.in");
  30. int n,i, fin,inc, prof;
  31. f>>n;
  32. activitate aux;
  33. vector<activitate> activitati;
  34. vector<activitate> solutie;
  35. for(i=0;i<n;i++)
  36. {
  37. f>>aux.inceput>>aux.fin>>aux.profit;
  38. activitati.push_back(aux);
  39. }
  40.  
  41. sort(activitati.begin(),activitati.end(),compareProfit);
  42.  
  43. solutie.push_back(activitati[0]);
  44. fin = solutie[0].fin;
  45. inc = solutie[0].inceput;
  46. prof = solutie[0].profit;
  47. for(i=1;i<n;i++)
  48. {
  49. if(activitati[i].inceput > fin)
  50. {
  51. solutie.push_back(activitati[i]);
  52. fin = activitati[i].fin;
  53. inc = activitati[i].inceput;
  54. }
  55.  
  56. }
  57.  
  58. for(i=0;i<solutie.size();i++)
  59. {
  60. cout<<solutie[i].inceput<<" "<<solutie[i].fin<<" "<<solutie[i].profit;
  61. cout<<endl;
  62. }
  63.  
  64. return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment