POJ

http://poj.org/problem?id=2159

题意:给一种加密方式:先打乱,然后把字母换掉。求s串可不可以是t串的密文。

发现就是这种“可以”的情况就是字母的频率图排序后相同。

#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;

int cnts[26];
int cntt[26];

int main() {
#ifdef Yinku
    freopen("Yinku.in", "r", stdin);
#endif // Yinku
    string s, t;
    while(cin >> s >> t) {
        for(int i = 0; i < s.length(); ++i) {
            cnts[s[i] - 'A']++;
        }
        for(int i = 0; i < t.length(); ++i) {
            cntt[t[i] - 'A']++;
        }
        sort(cnts, cnts + 26);
        sort(cntt, cntt + 26);
        bool suc = 1;
        for(int i = 0; i < 26; ++i) {
            if(cnts[i] != cntt[i])
                suc = 0;
        }
        puts(suc ? "YES" : "NO");
    }
}
原文地址:https://www.cnblogs.com/Inko/p/11723347.html