Encrypted Password UVALive

来源:互联网 发布:乐高蝙蝠侠大电影知乎 编辑:程序博客网 时间:2024/06/10 06:19

题目链接:

Encrypted Password

UVALive - 6320


                                                                                                   

tho:      n 方会超时, 所以就转换成 n*26 的算法



#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;}