Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- #include<conio.h>
- #include <cmath>
- using namespace std;
- int n; // numarul spectacolelor !
- float O[100][3];
- float compute(float start, int duration)
- {
- float ora_h = 0;
- ora_h = floor(start);
- float minutesLeft = start - ora_h;
- minutesLeft *= 100;
- minutesLeft += duration;
- int plus_h;
- plus_h= floor(minutesLeft / 60);
- minutesLeft=minutesLeft-plus_h*60;
- ora_h=ora_h+plus_h;
- minutesLeft = int(ceil(minutesLeft)) % 60;
- minutesLeft /= 100;
- ora_h += minutesLeft;
- return ora_h; }
- int read_data()
- {
- fstream f;
- f.open("input.dat",ios::in);
- f>>n;
- for(int i=1;i<=n;i++)
- {
- f>>O[i][1]; // ora de inceput
- f>>O[i][2]; // durata
- O[i][3]=compute(O[i][1],O[i][2]); // ora de sfarsit
- }
- }
- int sort_data()
- {
- int aux,schimb,i;
- do
- {
- schimb=0;
- for (i=1;i<n;i++)
- if (O[i][3]>O[i+1][3])
- {
- swap(O[i][3],O[i+1][3]);
- swap(O[i][1],O[i+1][1]);
- swap(O[i][2],O[i+1][2]);
- schimb=1;
- }
- }
- while (schimb);
- }
- int print_data()
- {
- /*
- input.dat
- 4
- 8.10 40
- 7.00 20
- 11.30 30
- 10.45 45
- de afisat
- 7.00 20
- 8.10 40
- 10.45 45
- 11.30 30
- */
- for(int i=1;i<=n;i++)
- cout<<O[i][1]<<" "<<O[i][2]<<endl;
- }
- int main()
- {
- read_data();
- sort_data();
- print_data();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement