Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. class Sana{
  7.     private:
  8.         vector<string>reci;
  9.         int dovde;
  10.         int velicina;
  11.     public:
  12.         Sana(){
  13.             this->dovde = 0;
  14.             this->velicina = 0;
  15.         }
  16.         void dodajRec(string rec){
  17.             reci.push_back(rec);
  18.             velicina++;
  19.         }
  20.         void srt(){
  21.             sort(begin(reci), end(reci));
  22.         }
  23.         string dajRec(){
  24.             string r = reci[dovde];
  25.             dovde = (dovde + 1) % velicina;
  26.             return r;
  27.         }
  28.         bool prazno(){
  29.             return velicina == 0;
  30.         }
  31. };
  32.  
  33. int main(){
  34.  
  35.     int n; // broj reci
  36.     cin >> n;
  37.  
  38.     vector<Sana>mapa(26, Sana());
  39.     for(int i = 0; i<n; i++){
  40.         string rec;
  41.         cin >> rec;
  42.  
  43.         char c = rec[0];
  44.         int hash = c - 'a';
  45.         mapa[hash].dodajRec(rec);
  46.     }
  47.     for(int i = 0; i<26; i++){
  48.         mapa[i].srt();
  49.     }
  50.  
  51.     int k;
  52.     cin >> k;
  53.     for(int i = 0; i<k; i++){
  54.         char c;
  55.         cin >> c;
  56.  
  57.         int hash = c - 'a';
  58.         if(!mapa[hash].prazno()){
  59.             cout << mapa[hash].dajRec() << endl;
  60.         }
  61.     }
  62.    
  63.  
  64.  
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement