题目链接:
Encrypted Password
UVALive - 6320
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#define inf 0x3f3f3f
#define ms(x) memset(x,0,sizeof(x))
using namespace std;
int main()
{
int T;
char s[100123];
char t[100123];
int book[30];
int vis[30];
while(cin>>T)
{
while(T--)
{
ms(book);
ms(vis);
scanf("%s",s);
scanf("%s",t);
int ls = strlen(s);
int lt = strlen(t);
for(int i=0;i<lt;i++)
{
vis[s[i]-'a']++; //生成串
book[t[i]-'a']++; //原串
}
int f;
for(int i=0;i+lt<=ls;i++)
{
f=1;
for(int j=0;j<27;j++)
{
if(book[j]!=vis[j])
{
f=0;break;
}
}
vis[s[i]-'a']--;
vis[s[i+lt]-'a']++;
if(f) break;
}
if(f) printf("YES\n");
else printf("NO\n");
}
}
return 0;
}