Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- using namespace std;
- int n,m,s[20];
- struct activ
- { int x,y,z;
- };
- activ a[20],aux;
- void citire(int &n)
- { ifstream f("e:\\info\\greedy\\spectacol.txt");
- f>>n;
- for(int i=1;i<=n;i++)
- f>>a[i].x>>a[i].y>>a[i].z;
- f.close();
- }
- void afisare()
- { for(int i=1;i<=n;i++)
- { cout<<a[i].x<<" "<<a[i].y<<" "<<a[i].z;
- cout<<endl;
- }
- }
- void sortare()
- { activ aux;
- for(int i=1;i<n;i++)
- for(int j=i+1;j<=n;j++)
- if(a[i].z>a[j].z)
- { aux=a[i];
- a[i]=a[j];
- a[j]=aux;
- }
- }
- void greedy(int &m)
- { int j=1;s[1]=1;
- for(int i=2;i<=n;i++)
- if(a[i].y>=a[s[j]].z)
- { j++;
- s[j]=i;
- }
- m=j;
- }
- void afis()
- { for(int i=1;i<=m;i++)
- cout<<"activitatea "<<a[s[i]].x<<" ora de inceput "<<a[s[i]].y<<" ora de sfarsit "<<a[s[i]].z<<endl;
- }
- int main()
- { citire(n);
- afisare();
- cout<<endl;
- sortare();
- afisare();
- cout<<endl;
- greedy(m);
- afis();
- }
- 8
- 1 9 11
- 2 12 13
- 3 8 10
- 4 10 12
- 5 16 18
- 6 14 16
- 7 20 22
- 8 19 21
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement