Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int n, m, x;
- string s[1111];
- void radix (int y) {
- for (int i = m - 1; i >= m - y; --i) {
- string t[1111];
- int c[26];
- for (int j = 0; j < 26; ++j) {
- c[j] = 0;
- }
- for (int j = 0; j < n; ++j) {
- int d = s[j][i] - 'a';
- c[d]++;
- }
- int cnt = 0;
- for (int j = 0; j < 26; ++j) {
- int tmp = c[j];
- c[j] = cnt;
- cnt += tmp;
- }
- for (int j = 0; j < n; ++j) {
- int d = s[j][i] - 'a';
- t[c[d]] = s[j];
- c[d]++;
- }
- for (int j = 0; j < n; ++j) {
- s[j] = t[j];
- }
- }
- }
- int main () {
- ios_base::sync_with_stdio(0);
- freopen("radixsort.in", "r", stdin);
- freopen("radixsort.out", "w", stdout);
- cin >> n >> m >> x;
- for (int i = 0; i < n; ++i) {
- cin >> s[i];
- }
- radix(x);
- for (int i = 0; i < n; ++i) {
- cout << s[i] << endl;
- }
- return 0;
- }
- /*
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement