// Test of two strings are anagrams
// By DreamVB 23:44 14/10/2016

#include <iostream>

using namespace std;
using std::cout;
using std::endl;

bool IsAnagram(char *srcA,char *SrcB){
	int i = 0;
	int j = 0;
	int LenA = 0;
	int LenB = 0;
	char s0[80];
	char s1[80];
	bool IsGood = true;

	strcpy(s0, srcA);
	strcpy(s1, SrcB);

	LenA = strlen(srcA);
	LenB = strlen(SrcB);

	//Check lengths
	if (LenA != LenB){
		return false;
	}

	//Convert chars to lowercase on SrcA
	while (i < LenA){
		s0[i] = tolower(s0[i]);
		i++;
	}

	//Convert chars to lowercase on SrcA
	while (j<LenB){
		s1[j] = tolower(s1[j]);
		j++;
	}

	//Sort s0 array
	for (i = 0; i < LenA; i++){
		for (j = i + 1; j < LenA; j++){
			if (s0[i] >s0[j]){
				//Swap two values.
				swap(s0[i], s0[j]);
			}
		}
	}

	//Sort s1 array
	for (i = 0; i < LenB; i++){
		for (j = i + 1; j < LenB; j++){
			if (s1[i] >s1[j]){
				//Swap two values.
				swap(s1[i], s1[j]);
			}
		}
	}

	//Reset i
	i = 0;
	//Compare the two char arrays
	while (i < LenA){
		if (s0[i] != s1[i]){
			IsGood = false;
			break;
		}
		i++;
	}

	return IsGood;
}

int main(int argc, char *argv[]){
	char s0[80];
	char s1[80];
	bool IsGood = true;

	cout << "Enter first string : ";
	//Get input from user.
	cin >> s0;
	cout << "Enter second text : ";
	cin >> s1;

	//Test two strings.
	IsGood = IsAnagram(s0, s1);

	if (IsGood){
		cout << s0 << " and " << s1 << " are anagrams." << endl;
	}
	else{
		cout << s0 << " and " << s1 << " are not anagrams." << endl;
	}

	system("pause");
	return 0;
}