MessageFlood 分类: 串 2015-06-18 17:00 10人阅读 评论(0) 收藏

MessageFlood

TimeLimit: 1500ms Memory limit: 65536K 有疑问?点这里^_^

题目描述

Well,how do you feel about mobile phone? Your answer would probably besomething like that "It's so convenient and benefits people alot". However, If you ask Merlin this question on the New Year'sEve, he will definitely answer "What a trouble! I have to keepmy fingers moving on the phone the whole night, because I have somany greeting message to send!" Yes, Merlin has such a long namelist of his friends, and he would like to send a greeting message toeach of them. What's worse, Merlin has another long name list ofsenders that have sent message to him, and he doesn't want to sendanother message to bother them Merlin is so polite that he alwaysreplies each message he receives immediately). So, before he beginsto send message, he needs to figure to how many friends are left tobe sent. Please write a program to help him. Here is something thatyou should note. First, Merlin's friend list is not ordered, and eachname is alphabetic strings and case insensitive. These names areguaranteed to be not duplicated. Second, some senders may send morethan one message to Merlin, therefore the sender list may beduplicated. Third, Merlin is known by so many people, that's why somemessage senders are even not included in his friend list.

输入

Thereare multiple test cases. In each case, at the first line there aretwo numbers n and m (1<=n,m<=20000), which is the number offriends and the number of messages he has received. And then thereare n lines of alphabetic strings(the length of each will be lessthan 10), indicating the names of Merlin's friends, one per line.After that there are m lines of alphabetic strings, which are thenames of message senders. The input is terminated by n=0.

输出

Foreach case, print one integer in one line which indicates the numberof left friends he must send.

示例输入


53

Inkfish

Henry

Carp

Max

Jericho

Carp

Max

Carp

0


示例输出


3

/*
用的字典树,<span style="font-family:华文楷体, serif;">因为发送有重复的,所以以发送的建树,总的进行查询</span>
*/:
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <time.h>
#include <cctype>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <string>
#include <iostream>
#include <algorithm>
#define RR freopen("input.txt","r",stdin)
#define WW freopen("output.txt","w",stdout)
#define INF 0x3f3f3f3f

using namespace std;

const int Max=20100;

struct node
{
    bool flag;
    node *next[26];
};
node * Creat()
{
    node *p;
    p=new node;
    p->flag=false;
    for(int i=0;i<26;i++)
    {
        p->next[i]=NULL;
    }
    return p;
}
void Build(char *s,node *head)
{
    node *p;
    p=head;
    int a;
    for(int i=0;s[i];i++)
    {
        if(s[i]>='A'&&s[i]<='Z')
        {
            a=s[i]+32-'a';
        }
        else
        {
            a=s[i]-'a';
        }
        if(p->next[a]==NULL)
        {
            p->next[a]=Creat();
        }
        p=p->next[a];
    }
    p->flag=true;
}
bool Rcher(char *s,node *head)
{
    node *p;
    p=head;
    int a;
    for(int i=0;s[i];i++)
    {
        if(s[i]>='A'&&s[i]<='Z')
        {
            a=s[i]+32-'a';
        }
        else
        {
            a=s[i]-'a';
        }
        if(p->next[a]==NULL)
        {
            return false;
        }
        p=p->next[a];
    }
    return p->flag;
}
int main()
{
    int n,m;
    char s[Max][11];
    char c[11];
    while(scanf("%d",&n),n)
    {
        scanf("%d",&m);
        node *head;
        head=Creat();
        for(int i=0;i<n;i++)
        {
            scanf("%s",s[i]);
        }
        for(int i=0;i<m;i++)
        {
            scanf("%s",c);
            Build(c,head);
        }
        int ans=0;
        for(int i=0;i<n;i++)
        {
            if(Rcher(s[i],head))
            {
                ans++;

            }
        }
        cout<<n-ans<<endl;
    }
    return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

原文地址:https://www.cnblogs.com/juechen/p/4722020.html