Advertisement
hadiuzzaman65

string anagram or not

Apr 13th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     string s1;
  9.     cin>>s1;
  10.     string s2;
  11.     cin>>s2;
  12.     sort(s1.begin(),s1.end());
  13.     sort(s2.begin(),s2.end());
  14.     bool flag=true;
  15.     if(s1.size()!=s2.size())
  16.     {
  17.         cout<< "string is not anagram";
  18.  
  19.     }
  20.     else
  21.     {
  22.         for(int i=0; i<s1.size(); i++)
  23.             if(s1[i] !=s2[i])
  24.                 flag=false;
  25.             if(flag==true)
  26.                 cout<<"string is anagram.";
  27.             else
  28.                 cout<< "string is not anagram.";
  29.  
  30.     }
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement