现在的位置: 首页 > 综合 > 正文

hdu1075 What Are You Talking About

2018年04月23日 ⁄ 综合 ⁄ 共 661字 ⁄ 字号 评论关闭

用map做的,很简单

code:

#include <map>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

map<string,string> dict;
map<string,string>::iterator it;

char tmp1[25],tmp2[25],word[25];
char sent[3030];

int main()
{
    //freopen("output.txt","w",stdout);
    scanf("%s",tmp1);
    while(scanf("%s",tmp1))
    {
        if(!strcmp(tmp1,"END"))break;
        scanf("%s",tmp2);
        dict[tmp2]=tmp1;
    }
    scanf("%s",tmp1);getchar();
    int len,i,j;
    while(gets(sent))
    {
        if(!strcmp(sent,"END"))break;
        len=strlen(sent);
        j=0;
        for(i=0;i<len;i++){
            if('a'<=sent[i] && sent[i]<='z')
            {
                word[j++]=sent[i];
            }
            else{
                word[j]='\0';
                it=dict.find(word);
                if(it!=dict.end())
                    cout<< it->second;
                else
                    printf("%s",word);
                printf("%c",sent[i]);
                j=0;
            }
        }
        puts("");
    }
    return 0;
}

抱歉!评论已关闭.