POJ - 2159 - Ancient Cipher = 水题

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

时间: 2024-08-11 10:04:53

POJ - 2159 - Ancient Cipher = 水题的相关文章

poj 2159 Ancient Cipher(水)

Ancient Cipher Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30695   Accepted: 10023 Description Ancient Roman empire had a strong government system with various departments, including a secret service department. Important documents w

UVa 1339 Ancient Cipher --- 水题

UVa 1339 题目大意:给定两个长度相同且不超过100个字符的字符串,判断能否把其中一个字符串重排后,然后对26个字母一一做一个映射,使得两个字符串相同 解题思路:字母可以重排,那么次序便不重要,可以分别统计两个字符串中的各个字母出现的次数,得到两个cnt[26]数组, 又由于可以进行映射,则可以直接对两个数组进行排序后判断是否相等(相当于原来相等的值的两个地方做映射) /* UVa 1339 Ancient Cipher --- 水题 */ #include <cstdio> #incl

POJ 2159 Ancient Cipher 难度:0

题目链接:http://poj.org/problem?id=2159 #include <cstring> #include <cstdio> #include <cctype> char ch1[102]; char ch2[102]; int n1[102]; int n2[102]; int ch1n[26]; int ch2n[26]; int main(){ scanf("%s %s",ch2,ch1); int len=strlen(c

POJ 2159 Ancient Cipher

题意:被题意杀了……orz……那个替换根本就不是ASCII码加几……就是随机的换成另一个字符…… 解法:只要统计每个字母的出现次数,然后把数组排序看相不相同就行了…… 代码: #include<stdio.h> #include<iostream> #include<algorithm> #include<string> #include<string.h> #include<math.h> #include<limits.h&

poj 2369 Permutations 置换水题

找循环节求lcm就够了,若答案是12345应该输出1,被坑了下. #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<algorithm> #include<cmath> using namespace std; #define INF 0x3FFFFFF #define MAXN 2222 #define eps 1e-6 i

poj 1006:Biorhythms(水题,经典题,中国剩余定理)

Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 110991   Accepted: 34541 Description Some people believe that there are three cycles in a person's life that start the day he or she is born. These three cycles are the physical,

poj 1002:487-3279(水题,提高题 / hash)

487-3279 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 236746   Accepted: 41288 Description Businesses like to have memorable telephone numbers. One way to make a telephone number memorable is to have it spell a memorable word or phras

POJ 1488 Tex Quotes --- 水题

POJ 1488 题目大意:给定一篇文章,将它的左引号转成 ``(1的左边),右引号转成 ''(两个 ' ) 解题思路:水题,设置一个bool变量标记是左引号还是右引号即可 /* POJ 1488 Tex Quotes --- 水题 */ #include <cstdio> #include <cstring> int main() { #ifdef _LOCAL freopen("D:\\input.txt", "r", stdin); #

poj 1003:Hangover(水题,数学模拟)

Hangover Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 99450   Accepted: 48213 Description How far can you make a stack of cards overhang a table? If you have one card, you can create a maximum overhang of half a card length. (We're as