简单的字符串模拟 用哈希表存下每个字符出现的次数,最后逐个比较即可
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <vector>
using namespace std;
string a, b;
int n;
int t;
int main(void)
{
scanf("%d", &t);
getchar();
while(t -- )
{
unordered_map<char, int> h1, h2;
getline(cin, a);
getline(cin, b);
for(int i = 0 ; i < a.size() ; i ++ ) h1[a[i]] ++, h2[b[i]] ++ ;
if(h1.size() != h2.size()) printf("GJX is unhappy\n");
else
{
bool success = true;
for(auto item : h1)
{
if(!h2.count(item.first))
{
success = false;
break;
}else
{
if(h1[item.first] != h2[item.first])
{
success = false;
break;
}
}
}
if(success) puts("GJX is happy");
else puts("GJX is unhappy");
}
}
return 0;
}