Advertisement
montimaj

DICTIONARY SEARCH

Apr 5th, 2014
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. // Create a text file called dictionary and store strings there
  2.  
  3. #include<iostream>
  4. #include<string>
  5. #include<map>
  6. #include<algorithm>
  7. #include<fstream>
  8. void sort_words(std::map<std::string,int> &m)
  9. {
  10.   std::ifstream d;
  11.   std::string s;
  12.   d.open("dictionary.txt");
  13.   while(std::getline(d,s) && d.is_open())
  14.   {      
  15.     std::sort(s.begin(),s.end());
  16.     m[s]++;
  17.   }
  18. }  
  19. int main()
  20. {  
  21.   std::map<std::string,int> m;    
  22.   sort_words(m);
  23.   std::string s1;
  24.   std::cout<<"Enter input string: ";
  25.   std::cin>>s1;
  26.   std::sort(s1.begin(),s1.end());
  27.   if(m[s1])
  28.     std::cout<<"Permutation found"<<"\n";
  29.   else
  30.     std::cout<<"Not found"<<"\n";
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement