zoukankan      html  css  js  c++  java
  • 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 were sent between provinces and the capital in encrypted form to prevent eavesdropping. The most popular ciphers in those times were so called substitution cipher and permutation cipher. 
    Substitution cipher changes all occurrences of each letter to some other letter. Substitutes for all letters must be different. For some letters substitute letter may coincide with the original letter. For example, applying substitution cipher that changes all letters from 'A' to 'Y' to the next ones in the alphabet, and changes 'Z' to 'A', to the message "VICTORIOUS" one gets the message "WJDUPSJPVT". 
    Permutation cipher applies some permutation to the letters of the message. For example, applying the permutation <2, 1, 5, 4, 3, 7, 6, 10, 9, 8> to the message "VICTORIOUS" one gets the message "IVOTCIRSUO". 
    It was quickly noticed that being applied separately, both substitution cipher and permutation cipher were rather weak. But when being combined, they were strong enough for those times. Thus, the most important messages were first encrypted using substitution cipher, and then the result was encrypted using permutation cipher. Encrypting the message "VICTORIOUS" with the combination of the ciphers described above one gets the message "JWPUDJSTVP". 
    Archeologists have recently found the message engraved on a stone plate. At the first glance it seemed completely meaningless, so it was suggested that the message was encrypted with some substitution and permutation ciphers. They have conjectured the possible text of the original message that was encrypted, and now they want to check their conjecture. They need a computer program to do it, so you have to write one.

    Input

    Input contains two lines. The first line contains the message engraved on the plate. Before encrypting, all spaces and punctuation marks were removed, so the encrypted message contains only capital letters of the English alphabet. The second line contains the original message that is conjectured to be encrypted in the message on the first line. It also contains only capital letters of the English alphabet. 
    The lengths of both lines of the input are equal and do not exceed 100.

    Output

    Output "YES" if the message on the first line of the input file could be the result of encrypting the message on the second line, or "NO" in the other case.

    Sample Input

    JWPUDJSTVP
    VICTORIOUS

    Sample Output

    YES


    由于顺序是可以改变的.
    所以考虑是否可以映射.只要存在字母对应出现的次数都相同.那么就可以通过映射得到.
    具体是开一个数组记录每个字母出现的次数...
    然后sort

     1 /*************************************************************************
     2     > File Name: code/poj/2159.cpp
     3     > Author: 111qqz
     4     > Email: rkz2013@126.com 
     5     > Created Time: 2015年09月23日 星期三 19时04分34秒
     6  ************************************************************************/
     7 
     8 #include<iostream>
     9 #include<iomanip>
    10 #include<cstdio>
    11 #include<algorithm>
    12 #include<cmath>
    13 #include<cstring>
    14 #include<string>
    15 #include<map>
    16 #include<set>
    17 #include<queue>
    18 #include<vector>
    19 #include<stack>
    20 #include<cctype>
    21 #define y1 hust111qqz
    22 #define yn hez111qqz
    23 #define j1 cute111qqz
    24 #define ms(a,x) memset(a,x,sizeof(a))
    25 #define lr dying111qqz
    26 using namespace std;
    27 #define For(i, n) for (int i=0;i<int(n);++i)  
    28 typedef long long LL;
    29 typedef double DB;
    30 const int inf = 0x3f3f3f3f;
    31 const int N=30;
    32 string st1,st2;
    33 int len;
    34 int a[N],b[N];
    35 
    36 
    37 bool cmp( int a,int b)
    38 {
    39     if (a>b) return true;
    40     return false;
    41 }
    42 int main()
    43 {
    44   #ifndef  ONLINE_JUDGE 
    45    freopen("in.txt","r",stdin);
    46   #endif
    47    ms(a,0);
    48    ms(b,0);
    49    cin>>st1>>st2;
    50    len = st1.length();
    51   // cout<<st1<<endl<<st2<<endl;
    52    for ( int i = 0 ; i < len ; i ++)
    53     {
    54     int tmp = st1[i]-'A';
    55     a[tmp]++;
    56     tmp = st2[i]-'A';
    57     b[tmp]++;
    58     }
    59    
    60    sort(a,a+26,cmp);
    61    sort(b,b+26,cmp);
    62   //  for ( int i = 0 ; i < 26 ; i++) cout<<"a[i]:"<<a[i]<<" b[i]"<<b[i]<<endl;
    63 
    64    bool flag = true;
    65    for ( int i = 0 ; i < 26 ; i++)
    66     {
    67     if (a[i]!=b[i])
    68     {
    69         flag = false;
    70         break;
    71     }
    72     }
    73    if (flag)
    74     {
    75     puts("YES");
    76     }
    77    else
    78     {
    79     puts("NO");
    80     }
    81     
    82    
    83  #ifndef ONLINE_JUDGE  
    84   fclose(stdin);
    85   #endif
    86     return 0;
    87 }
    View Code
  • 相关阅读:
    《分析的艺术》读书笔记
    MySql数据库文件frm的移植
    R语言学习笔记(一)
    GATE使用笔记(使用自带的GUI界面)
    如何解决 Endnote自动搜索word中中括号[ ]或者大括号{}内的文字
    java import中jar包的位置
    hello
    filebeatkafkaelk搭建
    android note3
    iOS 6 SDK: 在应用内展示App Store
  • 原文地址:https://www.cnblogs.com/111qqz/p/4833320.html
Copyright © 2011-2022 走看看