Hi,
I'm trying to solve few problems related to strings, In most of the cases, I know how to go about it(algorithm), but I don't know how to implement it using "strings".
//This program finds out, if given two strings are anagram or no?
#include <iostream>
#include <stdlib.h>
usingnamespace std;
bool Anagram(string a,string B)
{
int LenA = a.size();
int LenB = b.size();
if(LenA != LenB)
return 0;
string::iterator iA;
string::iterator iB;
// Now there are two ways to accomplish this:
// 1. Arrange each string in alphabetical order and just compare them.
// NOTE: Here compare is easy, a.compare(B); but how to arrange them in alphabetical order ? (Character repetition allowed)
// 2. Count each character in each string, and compare if the count of each characters in a matches with count of each characters in b .
return 0;
}
int main()
{
string s1,s2;
cout << "Enter string S1" << endl;
cin >> s1;
cout << "Enter string S2" << endl;
cin >> s2;
if(Anagram(s1,s2))
{
cout << "String :" << s1 << " and String : " << s2 << " are anagram.\n";
}
else
{
cout << "String :" << s1 << " and String : " << s2 << " are NOT anagram.\n";
}
return 0;
}
I've gone through the cplusplus link for string. But I'm not yet able to organize it to solve problem. Want to see some working example, or concepts on, how to implement the two approach I have described in above code snippet. Please help.