Advertisement
AlexandruDu

Lucrari

Dec 15th, 2020
490
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int n;
  6.  
  7. struct lucrare
  8. {
  9.     unsigned int h,p,cod;
  10. }v[1000];
  11.  
  12. void ord()
  13. {
  14.     for(int i=0;i<n-1;i++)
  15.         for(int j=i+1;j<n;j++)
  16.             if(v[i].h>v[j].h)
  17.                 swap(v[i],v[j]);
  18.             else
  19.                 if(v[i].h==v[j].h)
  20.                     if(v[i].p<v[j].p)
  21.                         swap(v[i],v[j]);
  22. }
  23.  
  24. void greedy()
  25. {
  26.     cout<<v[0].cod<<" ";
  27.     int s=0;
  28.     for(int i=1;i<n;i++)
  29.         if(v[i].h==v[i-1].h)
  30.             s+=v[i].p;
  31.         else
  32.             cout<<v[i].cod<<" ";
  33.     cout<<endl<<"suma penalizarilor "<<s;
  34. }
  35.  
  36. void citire()
  37. {
  38.     cout<<"n=";cin>>n;
  39.     for(int i=0;i<n;i++)
  40.     {
  41.         cout<<"Ora ";cin>>v[i].h;
  42.         cout<<"Penalizare ";cin>>v[i].p;
  43.         v[i].cod=i+1;
  44.     }
  45. }
  46.  
  47. int main()
  48. {
  49.     citire();
  50.     ord();
  51.     greedy();
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement