SHARE
TWEET

Untitled

a guest Oct 21st, 2019 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <fstream>
  4. using namespace std;
  5.  
  6. vector<string> CategorySort(vector<string>& a, int index) //index == category(razryad)
  7. {
  8.     vector <vector <string>> alphabet(26); //26 letters in alphabet
  9.     vector<string> res;
  10.  
  11.     for (int i = 0; i < a.size(); ++i)
  12.         alphabet[a[i][index] - 'a'].push_back(a[i]);//a[i] - string, index - the youngest razryad of a[i]
  13.  
  14.     for (int i = 0; i < alphabet.size(); ++i)
  15.         for (int j = 0; j < alphabet[i].size(); ++j)
  16.             res.push_back(alphabet[i][j]);
  17.        
  18.     return res;
  19. }
  20.  
  21. vector<string> radixSort(vector<string>& a, int m, int k)
  22. {
  23.     for (; m > 0 && k > 0; --m, --k)
  24.         a = CategorySort(a, m - 1);
  25.     return a;
  26. }
  27.  
  28. int main()
  29. {
  30.     ifstream fin("radixsort.in");
  31.     ofstream fout("radixsort.out");
  32.     int n, m, k;
  33.     cin >> n >> m >> k; //n - array`s size, m - string`s length, k - requests
  34.     vector<string> a(n);
  35.  
  36.     for (int i = 0; i < n; ++i)
  37.         cin >> a[i];
  38.    
  39.     vector<string> res = radixSort(a, m, k);
  40.  
  41.     for (int i = 0; i < res.size(); ++i)
  42.         cout << res[i] << endl;
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top