HDU1075 What Are You Talking About

翻译  

字典树 和 map 都可以

 字典树 265 MS63592 KB  

map  1906MS 36100 KB

View Code
/*
scanf printf gets dont apply to string
can only use cin or cout
*/

#pragma warning( disable: 4786 )  //防止stl里面的warning
#include <stdio.h>
#include <iostream>
#include <string>
#include <map>

using namespace std;   // cin / cout
using std::string;
using std::map;

int main()
{
    string str, str2;
    char c;
    map<string, string> mp;
//    str.resize(100);
    while(cin>>str)
    {
        if( str == "END" )
            break;
        if(str == "START")
            continue;
        cin >> str2 ;
        mp[str2] = str;
    }
    cin >> str; getchar();  // 缓冲中保留\n
    str = "" ;
    while(1)
    {
        while( c = getchar() )
        {
            if(c <= 'z' && c>= 'a')
                str += c;
            else break;
        }
        if( c == 'E' )
            break;
        if( mp.find(str) != mp.end() )
            cout<<mp[str];
        else
            cout<<str;
        printf("%c", c);
        str = "" ;
    }    
    cin >> str;  // 把最后ND输入完
    return 0;
}

 

posted @ 2013-03-12 16:53  April_Tsui  阅读(162)  评论(0编辑  收藏  举报