Shuffle Hashing
Posted karshey
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Shuffle Hashing相关的知识,希望对你有一定的参考价值。
题
输入:
5
abacaba
zyxaabcaabkjh
onetwothree
threetwoone
one
zzonneyy
one
none
twenty
ten
输出:
YES
YES
NO
YES
NO
又名:根据样例找规律。
一个哈希表的记录。
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;cin>>n;
while(n--)
{
string a,b;cin>>a>>b;
if(a.size()>b.size())
{
cout<<"NO"<<endl;
continue;
}
unordered_map<char,int>m1;
for(int i=0;a[i];i++)
{
m1[a[i]]++;
}
int flag=0;
for(int i=0;i<=b.size()-a.size();i++)
{
unordered_map<char,int>m2;
for(int j=0;j<a.size();j++)
{
m2[b[i+j]]++;
}
if(m1==m2)
{
flag=1;
break;
}
}
if(flag) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}
以上是关于Shuffle Hashing的主要内容,如果未能解决你的问题,请参考以下文章
深入一致性哈希(Consistent Hashing)算法原理,并附100行代码实现