Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<conio.h>
  4. #include <cmath>
  5. using namespace std;
  6. int n; // numarul spectacolelor !
  7. float O[100][3];
  8. float compute(float start, int duration)
  9. {
  10. float ora_h = 0;
  11. ora_h = floor(start);
  12. float minutesLeft = start - ora_h;
  13. minutesLeft *= 100;
  14. minutesLeft += duration;
  15. int plus_h;
  16. plus_h= floor(minutesLeft / 60);
  17. minutesLeft=minutesLeft-plus_h*60;
  18. ora_h=ora_h+plus_h;
  19. minutesLeft = int(ceil(minutesLeft)) % 60;
  20. minutesLeft /= 100;
  21. ora_h += minutesLeft;
  22. return ora_h; }
  23.  
  24. int read_data()
  25. {
  26. fstream f;
  27. f.open("input.dat",ios::in);
  28. f>>n;
  29. for(int i=1;i<=n;i++)
  30. {
  31. f>>O[i][1]; // ora de inceput
  32. f>>O[i][2]; // durata
  33. O[i][3]=compute(O[i][1],O[i][2]); // ora de sfarsit
  34. }
  35. }
  36.  
  37. int sort_data()
  38. {
  39. int aux,schimb,i;
  40. do
  41. {
  42. schimb=0;
  43. for (i=1;i<n;i++)
  44. if (O[i][3]>O[i+1][3])
  45. {
  46. swap(O[i][3],O[i+1][3]);
  47. swap(O[i][1],O[i+1][1]);
  48. swap(O[i][2],O[i+1][2]);
  49.  
  50. schimb=1;
  51. }
  52. }
  53. while (schimb);
  54.  
  55. }
  56.  
  57. int print_data()
  58. {
  59. /*
  60. input.dat
  61.  
  62. 4
  63. 8.10 40
  64. 7.00 20
  65. 11.30 30
  66. 10.45 45
  67.  
  68. de afisat
  69. 7.00 20
  70. 8.10 40
  71. 10.45 45
  72. 11.30 30
  73. */
  74.  
  75. for(int i=1;i<=n;i++)
  76. cout<<O[i][1]<<" "<<O[i][2]<<endl;
  77.  
  78. }
  79.  
  80. int main()
  81. {
  82. read_data();
  83. sort_data();
  84. print_data();
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement