Sid is obsessed with reading short stories. Being a CS student, he is doing some interesting frequency analysis with the books. He chooses strings and in such a way that .
Your task is to help him find the minimum number of characters of the first string he needs to change to enable him to make it an of the second string.
Note: A word x is an anagram of another word y if we can produce y by rearranging the letters of x.
Input Format
The first line will contain an integer, , representing the number of test cases. Each test case will contain a string having length , which will be concatenation of both the strings described above in the problem.The given string will contain only characters from to .
Constraints
Output Format
An integer corresponding to each test case is printed in a different line, i.e. the number of changes required for each test case. Print if it is not possible.
Sample Input
6aaabbbababcmnopxyyxxaxbbbxx
Sample Output
31-1201
Explanation
Test Case #01: We have to replace all three characters from the first string to make both of strings anagram. Here, = "aaa" and = "bbb". So the solution is to replace all character 'a' in string a with character 'b'. Test Case #02: You have to replace 'a' with 'b', which will generate "bb". Test Case #03: It is not possible for two strings of unequal length to be anagram for each other. Test Case #04: We have to replace both the characters of first string ("mn") to make it anagram of other one. Test Case #05: and are already anagram to each other. Test Case #06: Here S1 = "xaxb" and S2 = "bbxx". He had to replace 'a' from S1 with 'b' so that S1 = "xbxb" and we can rearrange its letter to "bbxx" in order to get S2.
#includeusing namespace std;int anagaram(string s){ // Complete this function map s1; map s2; int len = s.length(); if(len%2 != 0 ){ return -1; } for(int i = 0; i < len ;i++){ s1[s[i]]=0; s2[s[i]]=0; } int count=0; int half = len / 2;//half = 4(0~7,8个元素) for(int i = 0 ;i < half;i++){ s1[s[i]]++; s2[s[i + half]]++; } map ::iterator it; for(it = s1.begin();it!=s1.end();it++) { int tmp = it->second-s2[it->first]; if(tmp>=0) count += tmp; } return count;}int main() { int q; cin >> q; for(int a0 = 0; a0 < q; a0++){ string s; cin >> s; int result = anagaram(s); cout << result << endl; } return 0;}