Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- bool comp(pair<int, string> a, pair<int, string> b)
- {
- return (a.first < b.first);
- }
- int main()
- {
- ios_base :: sync_with_stdio(0);
- cin.tie(0);
- #ifndef ONLINE_JUDGE
- freopen("in.txt", "r", stdin);
- #endif
- int i, j, k, n, m, tc;
- string s;
- cin >> tc;
- while(tc--) {
- cin >> n >> m;
- vector< pair<int, string> > dna(m);
- for(i = 0; i < m; i++) {
- cin >> s;
- dna[i] = make_pair(0, s); // dna[i].first = 0, dna[i].second = s;
- }
- for(i = 0; i < m; i++) {
- int count = 0;
- for(j = 0; j < n-1; j++) {
- for(k = j+1; k < n; k++) {
- if(dna[i].second[j] > dna[i].second[k]) count++;
- }
- }
- dna[i].first = count;
- }
- sort(dna.begin(), dna.end(), comp);
- for(i = 0; i < m; i++) cout << dna[i].second << endl;
- if(tc) cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement