HDOJ1075字典翻译(map应用)

#include<iostream>
#include<cstdio>
#include<map>
#include<string>
#include<cstring>
using namespace std;
const int SIZE=10000+16;
char book[SIZE];

map<string, string> dic;

void fun_in()
{
    char start[6]={''};
    scanf("%s",start);
    getchar();
    string y;
    while(cin>>y&&y.compare("END"))
    {
        string x;
        cin>>x;
        dic[x]=y;
    }
}

bool letter(char a)
{
    if('a'<=a&&a<='z')
        return true;
    return false;
}

void fun_out()
{
    char start[6]={''};
    scanf("%s",start);
    getchar();
    while(gets(book)&&strcmp(book,"END")!=0)
    {
        int r=0;
        while(book[r])
        {
            char lett[SIZE]={''};
            int l=0;
            while(letter(book[r])&&book[r])
            {
                lett[l++]=book[r++];
            }
            
            string k=lett;
            if(dic.find(k)!=dic.end())
            {
                cout<<dic[k];
            }
            else
            {
                cout<<lett;    
            }
            
            char fu[SIZE]={''};
            l=0;
            while(!letter(book[r])&&book[r])
            {
                fu[l++]=book[r++];
            }
            
            k=fu;
            if(dic.find(k)!=dic.end())
            {
                cout<<dic[k];
            }
            else
            {
                cout<<fu;    
            }
            
        }
        printf("
");        
    }
    
}

int main()
{
    fun_in();
    fun_out();
    
    return 0;
}
原文地址:https://www.cnblogs.com/program-ccc/p/4700609.html