Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- ifstream f("progr.in");
- struct spec
- {
- int ti, ts, td, nr;
- } a[100];
- int i, j, n;
- void citire()
- {
- f>>n;
- for(i=1; i<=n; i++)
- {
- f>>a[i].ti;
- f>>a[i].ts;
- a[i].td=a[i].ts-a[i].ti;
- }
- }
- void ordonare()
- {
- spec aux;
- for(i=1; i<=n; i++)
- for(j=1; j<=n; j++)
- if(a[i].ts<a[j].ts)
- {
- aux=a[i];
- a[i]=a[j];
- a[j]=aux;
- }
- }
- void afis()
- {
- cout<<"Spectacolul "<<1<<" dureaza "<<a[1].td<<"ore. [ "<<a[1].ti<<" - "<<a[1].ts<<" ]"<<endl;
- for(i=2; i<=n; i++)
- if(a[i].ti >= a[i-1].ts)
- {
- cout<<"Spectacolul "<<i<<" dureaza "<<a[i].td<<"ore. [ "<<a[i].ti<<" - "<<a[i].ts<<" ]"<<endl;
- }
- }
- int main()
- {
- citire();
- ordonare();
- afis();
- return 0;
- }
- /* Exemplu:
- "progr.in"
- 6 //nr spectacole
- 18 20 //spec nr 1
- 10 12 //spec nr 2
- 15 18 //spec nr 3
- 20 23 //spec nr 4
- 15 16 //spec nr 5
- 16 17 //spec nr 6
- Se v-a afisa:
- Spectacolul 2 [ 10 - 12 ]
- Spectacolul 5 [ 15 - 16 ]
- Spectacolul 6 [ 16 - 17 ]
- Spectacolul 1 [ 18 - 20 ]
- Spectacolul 4 [ 20 - 23 ]
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement