您的位置:首页 > 其它

UVa1339 - Ancient Cipher

2015-11-10 22:41 330 查看
题意:给出两个字符串,看是否是经过加密的,主要有两种加密方式,一种是替换加密,一种是排列加密(改变顺序)
思路:统计字符出现的次数,然后将次数排序,看是否相等
代码如下:

#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 26;

int c1
, c2
;

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: