Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions anagram.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <bits/stdc++.h>
using namespace std;

bool Anagram(string str1, string str2)
{
int n1 = str1.length();
int n2 = str2.length();

if (n1 != n2)
return false;

sort(str1.begin(), str1.end());
sort(str2.begin(), str2.end());

for (int i = 0; i < n1; i++)
if (str1[i] != str2[i])
return false;

return true;
}

int main()
{
string str1;
string str2;
cout<<"Enter the first string : ";
cin>>str1;
cout<<"Enter the second string : ";
cin>>str2;
if (Anagram(str1, str2))
cout << "The two strings are anagram of each other";
else
cout << "The two strings are not anagram of each other";

return 0;
}