Ancient Cipher

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>

using std::sort;

int count1[26], count2[26];
char str1[110], str2[110];

int main()
{
	while(~scanf("%s", str1))
	{
		scanf("%s", str2);
		int len1 = strlen(str1), len2 = strlen(str2);
		if(len1 != len2)
		{
			printf("NO\n");
			continue;
		}
		memset(count1, 0, sizeof(count1));
		memset(count2, 0, sizeof(count2));
		for(int i = 0; i < len1; ++i)
		{
			++count1[str1[i]-'A'];
			++count2[str2[i]-'A'];
		}
		sort(count1, count1+26);
		sort(count2, count2+26);
		bool ans = true;
		for(int i = 0; i < 26; ++i)
			if(count1[i] != count2[i])
			{
				ans = false;
				break;
			}
		if(ans)
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}

你可能感兴趣的:(Ancient Cipher)