Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- void Sortowanie(double tab[][2], int siz)
- {
- int k;
- for(int i=0;i<siz;i++)
- {
- k=i;
- for(int j=i+1;j<siz;j++)
- if(tab[j][0]>tab[k][0])
- k=j;
- swap(tab[k][0],tab[i][0]);
- swap(tab[k][1],tab[i][1]);
- }
- }
- int main()
- {
- string p[10];
- int n;
- double stosunek[10][2],c[10],w[10],waga,max_waga=0;;
- cout <<"ile przedmiotow?"<<endl;
- cin>>n;
- int ile[n];
- for(int i=0;i<n;i++)
- ile[i]=0;
- cout <<"jaka waga?"<<endl;
- cin >>waga;
- cout <<"podaj przedmiot, wage i wartosc"<<endl;
- for (int i=0;i<n;i++)
- {
- cin>>p[i]>>c[i]>>w[i];
- }
- for (int i=0;i<n;i++)
- {
- stosunek[i][0]=w[i]/c[i];
- stosunek[i][1]=i;
- }
- Sortowanie(stosunek,n);
- int co=0;
- while(co<n)
- {
- int ktory=stosunek[co][1];
- if((max_waga+c[ktory])<=waga)
- {
- max_waga+=c[ktory];
- ile[ktory]+=1;
- }
- else
- co++;
- }
- cout <<"WEZ:"<<endl;
- for(int i=0;i<n;i++)
- {
- if(ile[i]!=0)
- cout <<ile[i]<<"x "<<p[i]<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement