//Write a method to decide if two strings are anagrams or not
#include<iostream>
#include<string>
#define TRUE 1;
#define FALSE 0;
using namespace std;
string sort(string &s1)
{
//bubble
for(int i=0;i<s1.length();i++)
{
for(int j=0;j<s1.length()-i-1;j++)
{
if(s1[j]>s1[j+1])
{
char temp=s1[j];
s1[j]=s1[j+1];
s1[j+1]=temp;
}
}
}
return s1;
}
int anagrams(string s1, string s2)
{
if(s1==s2)
{
cout<<"two strings are same strings"<<endl;
return FALSE;
}
else if(s1.length()!=s2.length())
{
return FALSE;
}
else
{
if(sort(s1)==sort(s2))
return TRUE;
}
}
void main()
{
string s1,s2;
cout<<"please input s1:"<<endl;
cin>>s1;
cout<<"please input s2:"<<endl;
cin>>s2;
if(anagrams(s1,s2))
cout<<"two strings are anagrams"<<endl;
else
cout<<"two strings are not anagrams"<<endl;
}
#include<iostream>
#include<string>
#define TRUE 1;
#define FALSE 0;
using namespace std;
string sort(string &s1)
{
//bubble
for(int i=0;i<s1.length();i++)
{
for(int j=0;j<s1.length()-i-1;j++)
{
if(s1[j]>s1[j+1])
{
char temp=s1[j];
s1[j]=s1[j+1];
s1[j+1]=temp;
}
}
}
return s1;
}
int anagrams(string s1, string s2)
{
if(s1==s2)
{
cout<<"two strings are same strings"<<endl;
return FALSE;
}
else if(s1.length()!=s2.length())
{
return FALSE;
}
else
{
if(sort(s1)==sort(s2))
return TRUE;
}
}
void main()
{
string s1,s2;
cout<<"please input s1:"<<endl;
cin>>s1;
cout<<"please input s2:"<<endl;
cin>>s2;
if(anagrams(s1,s2))
cout<<"two strings are anagrams"<<endl;
else
cout<<"two strings are not anagrams"<<endl;
}