Advertisement
arif334

UVa 612

Jan 16th, 2023 (edited)
761
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5. bool comp(pair<int, string> a, pair<int, string> b)
  6. {
  7.     return (a.first < b.first);
  8. }
  9.  
  10. int main()
  11. {
  12.     ios_base :: sync_with_stdio(0);
  13.     cin.tie(0);
  14.  
  15.     #ifndef ONLINE_JUDGE
  16.         freopen("in.txt", "r", stdin);
  17.     #endif
  18.  
  19.     int i, j, k, n, m, tc;
  20.     string s;
  21.  
  22.     cin >> tc;
  23.     while(tc--) {
  24.         cin >> n >> m;
  25.        
  26.         vector< pair<int, string> > dna(m);
  27.         for(i = 0; i < m; i++) {
  28.             cin >> s;
  29.             dna[i] = make_pair(0, s); // dna[i].first = 0, dna[i].second = s;
  30.         }
  31.        
  32.         for(i = 0; i < m; i++) {
  33.             int count = 0;
  34.             for(j = 0; j < n-1; j++) {
  35.                 for(k = j+1; k < n; k++) {
  36.                     if(dna[i].second[j] > dna[i].second[k]) count++;
  37.                 }
  38.             }
  39.             dna[i].first = count;
  40.         }
  41.        
  42.         sort(dna.begin(), dna.end(), comp);
  43.        
  44.         for(i = 0; i < m; i++) cout << dna[i].second << endl;
  45.        
  46.         if(tc) cout << endl;
  47.     }
  48.  
  49.     return 0;
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement