思路:

因为不同病毒特征码不会相同。

AC自动机,然后对于每一个输出即可。

注意:以上字符串中字符都是ASCII码可见字符(不包括回车);G++ MLE。

//#include <bits/stdc++.h>
#include<iostream>
#include<queue>
#include<cstdio>
#include<string.h>
#include<algorithm>
using namespace std; const int N=1e5+10;    //500个串,长度为200 struct Trie{
    int num;
    Trie *next[128],*fail;
};
Trie q[N],*root;
int tol; Trie* Creat()
{
    Trie *p;
    p=&q[tol++];
    p->fail=NULL;
    p->num=0;
    for(int i=0;i<128;i++)
        p->next[i]=NULL;
    return p;
} void Insert(char *str,int num)
{
    int len=strlen(str),index;
    Trie *p=root;
    for(int i=0;i<len;i++)
    {
        index=str[i];
        if(p->next[index]==NULL)
            p->next[index]=Creat();
        p=p->next[index];
    }
    p->num=num;
} void Build_Ac()
{
    queue<Trie*>que;
    que.push(root);
    while(!que.empty())
    {
        Trie *p=que.front();que.pop();
        for(int i=0;i<128;i++)
        {
            if(p->next[i]!=NULL)
            {
                if(p==root) p->next[i]->fail=root;
                else{
                    Trie *temp=p->fail;
                    while(temp!=NULL)
                    {
                        if(temp->next[i]!=NULL) {
                            p->next[i]->fail=temp->next[i];
                            break;
                        }
                        temp=temp->fail;
                    }
                    if(temp==NULL)
                        p->next[i]->fail=root;
                }
                que.push(p->next[i]);
            }
        }
    }
} int ans[510],nn;
char word[10010];
void Query()
{
    Trie *p=root;
    int index,len=strlen(word);
    for(int i=0;i<len;i++)
    {
        index=word[i];
        while(p!=root && p->next[index]==NULL)
            p=p->fail;
        p=p->next[index];
        if(p==NULL)
            p=root;
        Trie *temp=p;
        while(temp!=root)
        {
            if(temp->num)
                ans[nn++]=temp->num;
            temp=temp->fail;
        }
    }
} char s[220];
int main()
{
    tol=0;
    root=Creat();
    int n,m;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%s",s);
        Insert(s,i);
    }
    Build_Ac();
    scanf("%d",&m);
    int sum=0;
    for(int i=1;i<=m;i++)
    {
        scanf("%s",word);
        nn=0;
        Query();
        if(nn)
        {
            sum++;
            sort(ans,ans+nn);
            printf("web %d:",i);
            for(int i=0;i<nn;i++)
                printf(" %d",ans[i]);
            puts("");
        }
    }
    printf("total: %d\n",sum);
    return 0;
}

最新文章

  1. [LeetCode] Gas Station 加油站问题
  2. Sublime Text 基础配置
  3. Mysql查看执行计划-explain
  4. js获取Html元素的实际宽度高度
  5. iOS开发网络篇—简单介绍ASI框架的使用
  6. ubuntu下安装kde Plasma
  7. navicat 或者workbench 无法连接127.0.0.1(61)的解决方法
  8. Android开发UI之ListView中的Button点击设置
  9. google code 上传源码
  10. cf B. The Fibonacci Segment
  11. android面试题 不仅仅是面试是一个很好的学习
  12. 创建和使用SQL Server SSAS本地多维数据集
  13. 从《海贼王》的视角走进BAT的世界(百度/阿里/腾讯)
  14. 记录一次CentOS环境升级Python2.6到Python2.7并安装最新版pip
  15. [SDOI2011]染色
  16. 使用http服务提供yum源
  17. Spring.Net 简单实例-01(IOC)
  18. Linux给普通用户增加ssh权限
  19. J2EE完全手册(二)
  20. 提交代码到自己的github仓库

热门文章

  1. 二进制安装Mysql 5.6(免编译)
  2. iOS用户是否打开APP通知开关跳转到系统的设置界面
  3. asp.net mvc4 修改密码界面
  4. ideal 控制台乱码 解决
  5. objective-c的代码块block
  6. 让ansbile和docker愉快的在一起
  7. poj 3617 Best Cow Line 解题报告
  8. webrtc 学习资源
  9. 为什要使用预编译SQL?
  10. nginx开发_ngx_palloc源码解析