zoukankan      html  css  js  c++  java
  • POJ2159 ancient cipher

    2017-08-31 20:11:39

    writer:pprp

    一开始说好这个是个水题,就按照水题的想法来看,唉~

    最后还是懵逼了,感觉太复杂了,一开始想要排序两串字符,然后移动之类的,但是看了看

    好像没有什么规律...

    然后就去膜大神code了

    其实转换了一个思路,对两个字符串分别统计每个的个数,

    然后分别排序,如果每个个数都可以对的上就说明可以通过两个操作得到

    代码如下:

    /*
    @theme:poj 2159 ancient cipher
    @writer:pprp
    @declare:
    @begin:19:20
    @end:20:07
    @date:2017/8/31
    */
    
    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    
    using namespace std;
    
    int main()
    {
        //freopen("in.txt","r",stdin);
        ios::sync_with_stdio(false);
    
        int a[26] = {0};
        int b[26] = {0};
    
        string str1, str2;
    
        cin >> str1 >> str2;
    
        for(int i = 0 ; i < str1.length() ; i++)
            a[str1[i] - 'A']++;
        for(int i = 0 ;i < str2.length() ; i++)
            b[str2[i] - 'A']++;
    
        sort(a,a+26);
        sort(b,b+26);
    
        int i;
        for(i = 0 ; i < 26 ; i++)
            if(a[i] != b[i])
            break;
    
        if(i != 26 )
            cout << "NO" << endl;
        else
            cout << "YES" << endl;
    
        return 0;
    }

    英语:

    encrypted 加密
    eavesdrop 偷听
    cipher 密码
    substitute 代替
    permutation 变换组合

  • 相关阅读:
    sublime text添加snippet
    python __globals__, __file__
    Zen of Python
    Python的魔法函数之
    tornado session
    sqlalchemy学习
    自控力
    无需编译、快速生成 Vue 风格的文档网站
    python描述符理解
    python property理解
  • 原文地址:https://www.cnblogs.com/pprp/p/7460312.html
Copyright © 2011-2022 走看看