1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
bool isAnagram(string s1, string s2);
void inputAna(string &s1, string &s2);
void outputAna(string s1, string s2, bool b);
int main()
{
string str1, str2;
inputAna(str1, str2);
bool b = isAnagram(str1, str2);
outputAna(str1, str2, b);
}
void inputAna(string &s1, string &s2)
{
//input
cout << "Enter a word: ";
getline(cin, s1);
cout << "Enter another word: ";
getline(cin, s2);
}
bool isAnagram(string s1, string s2)
{
bool b = false;
if (s1.length() == s2.length() )
{
sort(s1.begin(), s1.end());
sort(s2.begin(), s2.end());
if (s1 == s2)
{
b = true;
}
}
return b;
}
void outputAna(string s1, string s2, bool b)
{
if (b == true)
cout<<s1<<" and "<<s2<<" are anagrams.";
if (b == false)
cout<<s1<<" and "<<s2<<" are not anagrams.";
return;
}
|