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,waga;
- double stosunek[10][2],c[10],w[10];
- cout <<"ile przedmiotow?"<<endl;
- cin>>n;
- 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,3);
- for (int i=0;i<n;i++)
- {
- cout <<p[i]<<" "<<stosunek[i][0]<<" "<<stosunek[i][1]<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement