POJ 2159 Ancient Cipher

题意:问一个串经过两步加密后是否能得到另一个串。

加密步骤:1、先将每种字母各被某种字母替换,每种字母的替换字母各不相同。2、再将替换后的串打乱顺序。

分析:

1、因为替换字母各不相同,所以经过第一步加密后,所有字母出现次数的种类和个数是相同的。

2、第二步加密只是打乱顺序,并不影响所有字母出现次数的种类和个数。

3、所以直接统计比较两个串出现次数的种类和个数即可。

#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
const double eps = 1e-8;
inline int dcmp(double a, double b){
    if(fabs(a - b) < eps) return 0;
    return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 100 + 10;
const int MAXT = 10000 + 10;
using namespace std;
char a[MAXN], b[MAXN];
map<char, int> mp1;
map<char, int> mp2;
vector<int> v1, v2;
bool judge(){
    for(int i = 0; i < 26; ++i){
        if(v1[i] != v2[i]) return false;
    }
    return true;
}
int main(){
    scanf("%s%s", a, b);
    int len = strlen(a);
    for(int i = 0; i < len; ++i){
        ++mp1[a[i]];
        ++mp2[b[i]];
    }
    for(int i = 0; i < 26; ++i){
        v1.push_back(mp1['A' + i]);
        v2.push_back(mp2['A' + i]);
    }
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    if(judge()){
        printf("YES\n");
    }
    else printf("NO\n");
    return 0;
}

  

原文地址:https://www.cnblogs.com/tyty-Somnuspoppy/p/6505047.html