Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- class Sana{
- private:
- vector<string>reci;
- int dovde;
- int velicina;
- public:
- Sana(){
- this->dovde = 0;
- this->velicina = 0;
- }
- void dodajRec(string rec){
- reci.push_back(rec);
- velicina++;
- }
- void srt(){
- sort(begin(reci), end(reci));
- }
- string dajRec(){
- string r = reci[dovde];
- dovde = (dovde + 1) % velicina;
- return r;
- }
- bool prazno(){
- return velicina == 0;
- }
- };
- int main(){
- int n; // broj reci
- cin >> n;
- vector<Sana>mapa(26, Sana());
- for(int i = 0; i<n; i++){
- string rec;
- cin >> rec;
- char c = rec[0];
- int hash = c - 'a';
- mapa[hash].dodajRec(rec);
- }
- for(int i = 0; i<26; i++){
- mapa[i].srt();
- }
- int k;
- cin >> k;
- for(int i = 0; i<k; i++){
- char c;
- cin >> c;
- int hash = c - 'a';
- if(!mapa[hash].prazno()){
- cout << mapa[hash].dajRec() << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement