zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 78 (Rated for Div. 2) A. Shuffle Hashing

    链接:

    https://codeforces.com/contest/1278/problem/A

    题意:

    Polycarp has built his own web service. Being a modern web service it includes login feature. And that always implies password security problems.

    Polycarp decided to store the hash of the password, generated by the following algorithm:

    take the password p, consisting of lowercase Latin letters, and shuffle the letters randomly in it to obtain p′ (p′ can still be equal to p);
    generate two random strings, consisting of lowercase Latin letters, s1 and s2 (any of these strings can be empty);
    the resulting hash h=s1+p′+s2, where addition is string concatenation.
    For example, let the password p= "abacaba". Then p′ can be equal to "aabcaab". Random strings s1= "zyx" and s2= "kjh". Then h= "zyxaabcaabkjh".

    Note that no letters could be deleted or added to p to obtain p′, only the order could be changed.

    Now Polycarp asks you to help him to implement the password check module. Given the password p and the hash h, check that h can be the hash for the password p.

    Your program should answer t independent test cases.

    思路:

    暴力枚举

    代码:

    #include<bits/stdc++.h>
    using namespace std;
    
    map<char, int> Mp;
    string p, s;
    
    bool Check(int x)
    {
        map<char, int> Tmp;
        Tmp = Mp;
        for (int i = 0;i < (int)p.size();i++)
        {
            if (Tmp[s[i+x]] < 0)
                return false;
            Tmp[s[i+x]]--;
        }
        for (auto v: Tmp) if (v.second > 0)
            return false;
        return true;
    }
    
    
    int main()
    {
        int t;
        cin >> t;
        while(t--)
        {
            Mp.clear();
            cin >> p >> s;
            for (int i = 0;i < (int)p.size();i++)
                Mp[p[i]]++;
            bool flag = false;
            for (int i = 0;i < (int)s.size();i++) if (Check(i))
            {
                flag = true;
                break;
            }
            if (flag)
                cout << "YES" << endl;
            else
                cout << "NO" << endl;
        }
    
        return 0;
    }
    
  • 相关阅读:
    创建包含前后255天所有天数的视图。
    VC获取主机名和主机信息
    在PowerDesigner增加unique约束
    差集的几种计算方法
    动态列的处理(统计)。
    一个查询语句各个部分的执行顺序
    IDC机房跳线
    软件下载链接
    IDC装机检查思路
    运维工程师之IDC系列
  • 原文地址:https://www.cnblogs.com/YDDDD/p/12076341.html
Copyright © 2011-2022 走看看