• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆 - 6, 文章 - 0, 評論 - 24, 引用 - 0
            數(shù)據(jù)加載中……

            Trie在程序設計競賽中的應用

            Trie在程序設計競賽中的應用

            題目

             Message Flood
            Problem 

            Well, how do you feel about mobile phone? Your answer would probably be something like that “It’s so convenient and benefits people a lot”. However, if you ask Merlin this question on the New Year’s Eve, he will definitely answer “What a trouble! I have to keep my fingers moving on the phone the whole night, because I have so many greeting messages to send! ”. Yes, Merlin has such a long name list of his friends, and he would like to send a greeting message to each of them. What’s worse, Merlin has another long name list of senders that have sent message to him, and he doesn’t want to send another message to bother them (Merlin is so polite that he always replies each message he receives immediately). So, before he begins to send messages, he needs to figure to how many friends are left to be sent. Please write a program to help him. 

            Here is something that you should note. First, Merlin’s friend list is not ordered, and each name is alphabetic strings and case insensitive. These names are guaranteed to be not duplicated. Second, some senders may send more than one message to Merlin, therefore the sender list may be duplicated. Third, Merlin is known by so many people, that’s why some message senders are even not included in his friend list.

            Input

            There are multiple test cases. In each case, at the first line there are two numbers n and m (1<=n, m<=20000), which is the number of friends and the number of messages he has received. And then there are n lines of alphabetic strings (the length of each will be less than 10), indicating the names of Merlin’s friends, one per line. After that there are m lines of alphabetic strings, which are the names of message senders.

             The input is terminated by n=0. 

            Output

            For each case, print one integer in one line which indicates the number of left friends he must send. 

            Sample Input
            5 3
            Inkfish
            Henry
            Carp
            Max
            Jericho
            Carp
            Max
            Carp
            0
            Sample Output
            3


            代碼

             1#include <iostream>
             2#include <string>
             3#include "trie.h"
             4
             5struct Index {
             6    int operator[](char ch) {
             7        if (isupper(ch)) return ch - 'A';
             8        return ch - 'a';
             9    }

            10}
            ;
            11
            12int n, m;
            13std::string name;
            14trie<26, Index> name_set;
            15
            16int main() {
            17    while (std::cin>>n>>&& n) {
            18        name_set.clear();
            19        for (int i = 0; i < n; ++i) {
            20            std::cin>>name;
            21            name_set.insert(name.begin(), name.end());
            22        }

            23        int count = 0;
            24        while (m--{
            25            std::cin>>name;
            26            count += name_set.erase(name.begin(), name.end());
            27        }

            28        printf("%d\n", n - count);
            29    }

            30}

            31


            測試數(shù)據(jù)

            輸入數(shù)據(jù)
            輸出數(shù)據(jù)

            參考資料
            郭嵩山、張子臻、王磊、湯振東著  國際大學生程序設計競賽例題解(五)  電子工業(yè)出版社

            posted on 2009-03-28 11:45 yuyang7 閱讀(1707) 評論(0)  編輯 收藏 引用 所屬分類: 程序設計競賽

            日韩欧美亚洲综合久久影院Ds| 欧美成a人片免费看久久| 久久国产精品无码一区二区三区| 区久久AAA片69亚洲| 狠狠色丁香久久婷婷综合蜜芽五月 | 久久无码人妻一区二区三区| 亚洲av日韩精品久久久久久a| 国产亚洲美女精品久久久久狼| 激情久久久久久久久久| 一本久久a久久精品综合香蕉| 亚洲综合精品香蕉久久网| 狠狠狠色丁香婷婷综合久久五月| 9999国产精品欧美久久久久久| 天天影视色香欲综合久久| 国产精品一区二区久久不卡 | 久久婷婷国产综合精品| 国产成人久久777777| 亚洲乱码中文字幕久久孕妇黑人| 久久国产精品-国产精品| 国产精品久久久久久久久软件| 国产精品久久久天天影视| 一本色综合久久| 99热热久久这里只有精品68| 婷婷综合久久中文字幕蜜桃三电影 | 久久久久人妻精品一区三寸蜜桃| 久久国产欧美日韩精品免费| 国产欧美一区二区久久| 欧美黑人激情性久久| a级毛片无码兔费真人久久| 亚洲伊人久久大香线蕉综合图片| 国产三级观看久久| 色综合久久久久网| 久久午夜电影网| 狠狠色丁香久久婷婷综合五月| 伊人久久大香线蕉综合影院首页| 久久婷婷色综合一区二区| 99久久精品无码一区二区毛片| 精品久久久久久中文字幕人妻最新| 亚洲中文字幕无码久久综合网| 一本大道久久东京热无码AV| 国产免费久久精品99re丫y|