码迷,mamicode.com
首页 > 其他好文 > 详细

HDOJ1075字典翻译(map应用)

时间:2015-08-04 00:13:44      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:

#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]={\0};
    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]={\0};
    scanf("%s",start);
    getchar();
    while(gets(book)&&strcmp(book,"END")!=0)
    {
        int r=0;
        while(book[r])
        {
            char lett[SIZE]={\0};
            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]={\0};
            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("\n");        
    }
    
}

int main()
{
    fun_in();
    fun_out();
    
    return 0;
}

 

HDOJ1075字典翻译(map应用)

标签:

原文地址:http://www.cnblogs.com/program-ccc/p/4700609.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!