Advertisement
Nita_Cristian

Untitled

Nov 25th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. ifstream fin("binar.in");
  6. ofstream fout("binar.out");
  7.  
  8. int n, m;
  9. int indici[2001];
  10. char c[2001][2001];
  11.  
  12. void quick_sort(int st, int dr, int pas)
  13. {
  14.     if(dr <= st || pas >= n)
  15.         return;
  16.  
  17.     int pivot = 1;
  18.     int ps = st, pd = dr;
  19.  
  20.     if(ps < pd)
  21.     {
  22.         while(c[pas][indici[ps]] - '0' != pivot && ps < dr)
  23.         {
  24.             ps++;
  25.         }
  26.  
  27.         while(c[pas][indici[pd]] - '0' == pivot && pd > st)
  28.         {
  29.             pd--;
  30.         }
  31.  
  32.         if(ps <= pd && c[pas][indici[ps]] - '0' == pivot && c[pas][indici[pd]] -'0' != pivot)
  33.         {
  34.             swap(indici[ps], indici[pd]);
  35.         }
  36.     }
  37.     int mici = 0;
  38.     for(int i = st; i <= dr; i++)
  39.     {
  40.         if(c[pas][indici[i]] - '0' == pivot)
  41.         {
  42.             mici++;
  43.         }
  44.     }
  45.  
  46.     quick_sort(st, st + mici - 1, pas + 1);
  47.     quick_sort(st + mici, dr, pas + 1);
  48. }
  49.  
  50. int main()
  51. {
  52.     fin >> n >> m;
  53.  
  54.     for(int i = 0; i < m; i++)
  55.     {
  56.         indici[i] = i;
  57.     }
  58.  
  59.     for(int i = 0; i < n; i++)
  60.     {
  61.         fin >> c[i];
  62.     }
  63.  
  64.     quick_sort(0, 5, 0);
  65.  
  66.     for(int i = 0; i < m; i++)
  67.     {
  68.         fout << indici[i]+1 << ' ';
  69.     }
  70.  
  71.     fin.close();
  72.     fout.close();
  73.     return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement