Advertisement
SalmaYasser

Untitled

Oct 26th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. void find (string s , int k, vector <string> &res)
  2. {
  3. string word= "";
  4.  
  5. map < char , int > frq;
  6. map <string,bool> unq;
  7. int u = 0;
  8. int write = 0;
  9. for (int i = 0 ;i < s.size(); i ++)
  10. {
  11. char c = s[i];
  12. if (frq[c]==0)
  13. u++;
  14. frq[c]++;
  15. if (write < k)
  16. word+=c, write++;
  17. if (write == k)
  18. {
  19. if (u==k)
  20. {
  21. if (unq.find(word)== unq.end())
  22. res.push_back(word);
  23. unq[word]= true;
  24. }
  25. frq[word[0]]--;
  26. if (frq[word[0]] == 0)
  27. u--;
  28. word = word.substr(1,k-1);
  29. write--;
  30.  
  31. }
  32.  
  33. }
  34. }
  35.  
  36. int main() {
  37. vector <string> res;
  38. vector <string> acc = {"wagl", "aglk", "glkn", "lkna", "knag", "gawu", "awun", "wuna", "unag", "nagw", "agwk", "kwag"};
  39.  
  40. find("awaglknagawunagwkwagl",4,res);
  41.  
  42. for (string x : res)
  43. cout<<x<< " ";
  44. cout<<endl;
  45. for (string x : acc)
  46. cout<<x<< " ";
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement