Anagram : Two words are said to be anagrams of each other if the letters from one word can be rearranged to form the other word. From the above definition it is clear that two strings are anagrams if all characters in both strings occur same number of times. For example "abc" and "cab" are anagram strings, here every character 'a', 'b' and 'c' occur only one time in both strings. Our algorithm tries to find how many times characters appears in the strings and then comparing their corresponding counts.
First of all there is no any sence to compare two vectors that contain one element.
Here after the statement
length = word1.size();
length will be equal to 1 because each vector contains only one element
Here
if(word1[i] == word2[j])
{
count++;
}
in fact worda is compared with wordb ant they can be unequal though at the same time be anagrams.
I think you were going to compare characters of the both words not the words themselves.
But in any case the algorithm is invalid. Consider two words
"AAA"
and
"ABC"
If you will compare characters from the first word with characters from the second word then count will be equal to 3. HHowever this does not mean that the words are anagrams.