题意:给出两个字符串,看是否是经过加密的,主要有两种加密方式,一种是替换加密,一种是排列加密(改变顺序)
思路:统计字符出现的次数,然后将次数排序,看是否相等
代码如下:
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 26;
int c1[N], c2[N];
int main()
{
string s1, s2;
#ifndef ONLINE_JUDGE
ifstream fin("F:\\OJ\\uva_in.txt");
streambuf *old = cin.rdbuf(fin.rdbuf());
#endif
while (cin >> s1 >> s2)
{
if (s1.length() != s2.length())
{
cout << "NO" << endl;
continue;
}
memset(c1, 0, sizeof(c1));
memset(c2, 0, sizeof(c2));
for (string::size_type i = 0; i < s1.length(); i++)
{
c1[s1[i] - 'A']++;
c2[s2[i] - 'A']++;
}
sort(c1, c1 + N);
sort(c2, c2 + N);
if (memcmp(c1, c2, sizeof(c1)) != 0)
{
cout << "NO" << endl;
}
else
{
cout << "YES" << endl;
}
}
#ifndef ONLINE_JUDGE
cin.rdbuf(old);
#endif
return 0;
}