• <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
            數據加載中……

            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


            測試數據

            輸入數據
            輸出數據

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

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

            亚洲综合日韩久久成人AV| 亚洲狠狠综合久久| 久久AV无码精品人妻糸列| 色欲av伊人久久大香线蕉影院| 久久久久人妻精品一区| 国产精品久久久天天影视香蕉| 午夜精品久久影院蜜桃| 狠狠干狠狠久久| 亚洲国产成人久久一区WWW| 久久国产精品77777| 亚洲欧洲久久久精品| 久久久中文字幕| 97精品依人久久久大香线蕉97 | 日本精品久久久久中文字幕8 | 久久久久久国产精品无码下载| 久久99热只有频精品8| 久久亚洲精品国产精品婷婷| 狠狠色丁香久久婷婷综| 精品多毛少妇人妻AV免费久久| 国产免费久久精品丫丫| 久久丫精品国产亚洲av不卡| 亚洲婷婷国产精品电影人久久| 精品久久久久久无码免费| 狠狠色噜噜狠狠狠狠狠色综合久久| 久久精品国产AV一区二区三区| 最新久久免费视频| 久久婷婷五月综合色奶水99啪| 日韩中文久久| 久久综合九色欧美综合狠狠 | 伊人久久精品无码av一区| 人人狠狠综合久久亚洲| 久久夜色精品国产www| 99久久精品免费观看国产| 国产精品99久久久久久猫咪 | 欧美日韩中文字幕久久久不卡| 国产精品九九久久免费视频| 91精品国产91久久久久久青草| 国产国产成人久久精品| 国产高潮久久免费观看| 久久天天躁狠狠躁夜夜av浪潮| 久久免费大片|