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

Ancient Cipher UVA - 1339

程序员文章站 2022-04-02 10:10:08
...
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>

using namespace std;

int main() {
	string s1, s2;
	int cnt1[26], cnt2[26], flag = 1;
	while ((cin >> s1 >> s2).good()) {
		memset(cnt1, 0, sizeof(cnt1));
		memset(cnt2, 0, sizeof(cnt2));

		for (int i = 0; i < s1.length(); i++)
			cnt1[s1[i] - 'A']++;
		for (int i = 0; i < s2.length(); i++)
			cnt2[s2[i] - 'A']++;
		sort(begin(cnt1), end(cnt1));
		sort(begin(cnt2), end(cnt2));

		for (int i = 0; i < 26; i++)
			if (cnt1[i] != cnt2[i]) {
				flag = 0;
				break;
			}
		if (flag)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
		flag = 1;
	}
	return 0;
}