Advertisement
Guest User

Untitled

a guest
Nov 13th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int n, m, x;
  6. string s[1111];
  7.  
  8. void radix (int y) {
  9.      for (int i = m - 1; i >= m - y; --i) {
  10.         string t[1111];  
  11.         int c[26];
  12.         for (int j = 0; j <  26; ++j) {
  13.             c[j] = 0;
  14.         }
  15.         for (int j = 0; j < n; ++j) {
  16.             int d = s[j][i] - 'a';
  17.             c[d]++;
  18.         }
  19.         int cnt = 0;
  20.         for (int j = 0; j < 26; ++j) {
  21.             int tmp = c[j];
  22.             c[j] = cnt;
  23.             cnt += tmp;
  24.         }
  25.         for (int j = 0; j < n; ++j) {
  26.             int d = s[j][i] - 'a';
  27.             t[c[d]] = s[j];
  28.             c[d]++;
  29.         }    
  30.         for (int j = 0; j < n; ++j) {
  31.             s[j] = t[j];
  32.         }
  33.      }              
  34. }
  35.  
  36. int main () {
  37.  
  38.     ios_base::sync_with_stdio(0);
  39.  
  40.     freopen("radixsort.in", "r", stdin);
  41.     freopen("radixsort.out", "w", stdout);                                    
  42.  
  43.     cin >> n >> m >> x;
  44.     for (int i = 0; i < n; ++i) {
  45.         cin >> s[i];
  46.     }
  47.     radix(x);
  48.     for (int i = 0; i < n; ++i) {
  49.         cout << s[i] << endl;  
  50.     }
  51.    
  52.     return 0;
  53. }
  54.  
  55. /*
  56.  
  57.  
  58.  
  59. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement