欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

UVA - 1339 Ancient Cipher

程序员文章站 2022-04-02 10:06:08
...
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define maxn 105

int cmp(const void *a, const void *b)
{
	return *(int *)a - *(int *)b;
}

int main()
{
	int cnt1[30], cnt2[30];
	char s1[maxn], s2[maxn];
	while (scanf("%s%s", s1, s2) != EOF) {
		memset(cnt1, 0, sizeof(cnt1));
		memset(cnt2, 0, sizeof(cnt2));
		//printf("%s\n", s1);
		//printf("%s\n", s2);
		int len1 = strlen(s1);
		for (int i = 0; i < len1; ++i) {
			cnt1[s1[i] - 'A']++;
		}
		int len2 = strlen(s2);
		for (int i = 0; i < len2; ++i) {
			cnt2[s2[i] - 'A']++;
		}
		qsort(cnt1, 26, sizeof(int), cmp);
		qsort(cnt2, 26, sizeof(int), cmp);
		int flag = 1;
		for (int i = 0; i < 26; ++i) {
			//printf("%d: cnt1 = %d, cnt2 = %d\n", i, cnt1[i], cnt2[i]);
			if (cnt1[i] != cnt2[i]) {
				flag = 0;
				break;
			}
		}
		if (flag)
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0; 
}