Advertisement
elektryk798

plecak

Mar 18th, 2016
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. void Sortowanie(double tab[][2], int siz)
  7. {
  8.     int k;
  9.     for(int i=0;i<siz;i++)
  10.     {
  11.         k=i;
  12.         for(int j=i+1;j<siz;j++)
  13.         if(tab[j][0]>tab[k][0])
  14.             k=j;
  15.         swap(tab[k][0],tab[i][0]);
  16.         swap(tab[k][1],tab[i][1]);
  17.     }
  18. }
  19.  
  20. int main()
  21. {
  22.     string p[10];
  23.     int n,waga;
  24.     double stosunek[10][2],c[10],w[10];
  25.     cout <<"ile przedmiotow?"<<endl;
  26.     cin>>n;
  27.     cout <<"jaka waga?"<<endl;
  28.     cin >>waga;
  29.     cout <<"podaj przedmiot, wage i wartosc"<<endl;
  30.     for (int i=0;i<n;i++)
  31.     {
  32.         cin>>p[i]>>c[i]>>w[i];
  33.     }
  34.     for (int i=0;i<n;i++)
  35.     {
  36.         stosunek[i][0]=w[i]/c[i];
  37.         stosunek[i][1]=i;
  38.     }
  39.     Sortowanie(stosunek,3);
  40.     for (int i=0;i<n;i++)
  41.     {
  42.         cout <<p[i]<<"    "<<stosunek[i][0]<<"   "<<stosunek[i][1]<<endl;
  43.     }
  44.  
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement