SHARE
TWEET

Untitled

a guest Oct 23rd, 2019 68 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 == 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.     while (m > 0 && k > 0)
  24.     {
  25.         a = CategorySort(a, m - 1);
  26.         --m, --k;
  27.     }
  28.     return a;
  29. }
  30.  
  31. int main()
  32. {
  33.     ifstream fin("radixsort.in");
  34.     ofstream fout("radixsort.out");
  35.     int n, m, k;
  36.     fin >> n >> m >> k; //n - array`s size, m - string`s length, k - requests
  37.     vector<string> a(n);
  38.  
  39.     for (int i = 0; i < n; ++i)
  40.         fin >> a[i];
  41.      
  42.     vector<string> res = radixSort(a, m, k);
  43.  
  44.     for (int i = 0; i < res.size(); ++i)
  45.         fout << res[i] << endl;
  46. }
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
 
Top