Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define int long long
  3.  
  4. using namespace std;
  5. int n, k, f;
  6. int cnt[30];
  7. const int N = 1e3 + 228;
  8. string str[N], ar[N];
  9.  
  10. void radixLSD() {
  11. for (int i = k - 1; i >= max(k - f, 0LL); -- i) {
  12. for (int j = 0; j < 26; ++ j) {
  13. cnt[j] = 0;
  14. }
  15. for (int j = 0; j < n; ++ j) {
  16. cnt[ar[j][i] - 'a']++;
  17. }
  18. int ans = 0;
  19. int tmp;
  20. for (int j = 0; j < 26; ++j) {
  21. tmp = cnt[j];
  22. cnt[j] = ans;
  23. ans += tmp;
  24. }
  25. for (int j = 0; j < n; ++j) {
  26. //cout << cnt[ar[j][i] - 'a'] + 1 << endl;
  27. str[cnt[ar[j][i] - 'a']] = ar[j];
  28. cnt[ar[j][i] - 'a']++;
  29. }
  30. for (int j = 0; j < n; ++j) {
  31. ar[j] = str[j];
  32. }
  33. }
  34. }
  35.  
  36. int32_t main() {
  37. freopen("radixsort.in", "r", stdin);
  38. freopen("radixsort.out", "w", stdout);
  39. cin >> n >> k >> f;
  40. for (int i = 0; i < n; ++ i) {
  41. cin >> ar[i];
  42. }
  43. radixLSD();
  44. for (int i = 0 ; i < n; ++ i) {
  45. cout << ar[i] << endl;
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement