Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin("binar.in");
- ofstream fout("binar.out");
- int n, m;
- int indici[2001];
- char c[2001][2001];
- void quick_sort(int st, int dr, int pas)
- {
- if(dr <= st || pas >= n)
- return;
- int pivot = 1;
- int ps = st, pd = dr;
- if(ps < pd)
- {
- while(c[pas][indici[ps]] - '0' != pivot && ps < dr)
- {
- ps++;
- }
- while(c[pas][indici[pd]] - '0' == pivot && pd > st)
- {
- pd--;
- }
- if(ps <= pd && c[pas][indici[ps]] - '0' == pivot && c[pas][indici[pd]] -'0' != pivot)
- {
- swap(indici[ps], indici[pd]);
- }
- }
- int mici = 0;
- for(int i = st; i <= dr; i++)
- {
- if(c[pas][indici[i]] - '0' == pivot)
- {
- mici++;
- }
- }
- quick_sort(st, st + mici - 1, pas + 1);
- quick_sort(st + mici, dr, pas + 1);
- }
- int main()
- {
- fin >> n >> m;
- for(int i = 0; i < m; i++)
- {
- indici[i] = i;
- }
- for(int i = 0; i < n; i++)
- {
- fin >> c[i];
- }
- quick_sort(0, 5, 0);
- for(int i = 0; i < m; i++)
- {
- fout << indici[i]+1 << ' ';
- }
- fin.close();
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement