Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void find (string s , int k, vector <string> &res)
- {
- string word= "";
- map < char , int > frq;
- map <string,bool> unq;
- int u = 0;
- int write = 0;
- for (int i = 0 ;i < s.size(); i ++)
- {
- char c = s[i];
- if (frq[c]==0)
- u++;
- frq[c]++;
- if (write < k)
- word+=c, write++;
- if (write == k)
- {
- if (u==k)
- {
- if (unq.find(word)== unq.end())
- res.push_back(word);
- unq[word]= true;
- }
- frq[word[0]]--;
- if (frq[word[0]] == 0)
- u--;
- word = word.substr(1,k-1);
- write--;
- }
- }
- }
- int main() {
- vector <string> res;
- vector <string> acc = {"wagl", "aglk", "glkn", "lkna", "knag", "gawu", "awun", "wuna", "unag", "nagw", "agwk", "kwag"};
- find("awaglknagawunagwkwagl",4,res);
- for (string x : res)
- cout<<x<< " ";
- cout<<endl;
- for (string x : acc)
- cout<<x<< " ";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement