velimir

Sortiranje

Mar 22nd, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. struct pole{
  6.     string x;
  7.     double y;
  8. };
  9.  
  10. bool proverka(pole a, pole b)
  11. {
  12.     return a.y < b.y;
  13. }
  14.  
  15. int main()
  16. {
  17.     int brZbor, i, j;
  18.     cin >> brZbor;
  19.     pole zbor[brZbor];
  20.     for(i=0; i<brZbor; i++)
  21.     {
  22.         cin >> zbor[i].x;
  23.         zbor[i].y=0;
  24.         for(j=0; j<zbor[i].x.length(); j++)
  25.             zbor[i].y += zbor[i].x[j] -'A'+1;
  26.         zbor[i].y/=zbor[i].x.length();
  27.     }
  28.     stable_sort(zbor, zbor + brZbor, proverka);
  29.     for(i=0; i<brZbor; i++)
  30.     {
  31.         cout << zbor[i].x << endl;
  32.     }
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment