Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Create a text file called dictionary and store strings there
- #include<iostream>
- #include<string>
- #include<map>
- #include<algorithm>
- #include<fstream>
- void sort_words(std::map<std::string,int> &m)
- {
- std::ifstream d;
- std::string s;
- d.open("dictionary.txt");
- while(std::getline(d,s) && d.is_open())
- {
- std::sort(s.begin(),s.end());
- m[s]++;
- }
- }
- int main()
- {
- std::map<std::string,int> m;
- sort_words(m);
- std::string s1;
- std::cout<<"Enter input string: ";
- std::cin>>s1;
- std::sort(s1.begin(),s1.end());
- if(m[s1])
- std::cout<<"Permutation found"<<"\n";
- else
- std::cout<<"Not found"<<"\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement