hdu 1075 What Are You Talking About (map)

题目大意:

大概就要把句子翻译过来。给出了字典,和要翻译的句子。


用map<string ,string >  就可以模拟字典。


用一个临时的字符数组扫描。

在模拟的时候,如果碰到不是英文字母的。就把临时数组输出,然后再输出这个字符就可以了。


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

string str;
map<string,string>mp;

string ans;
char s[10000];
char tmp[1000];
int main()
{

    cin>>str;

    while(cin>>str)
    {
        if(str=="END")break;
        else
        {
            cin>>ans;
            mp[ans]=str;
        }
    }
    getchar();
    while(gets(s)!=NULL)
    {
        if(strcmp(s,"START")==0)continue;
        if(s[0]=='E' && s[1]=='N' && s[2]=='D')break;
        else
        {
            int len=strlen(s);

            int pos=0;

            while(pos<len)
            {
                int top=0;

                while(1)
                {
                    if(s[pos]<='z' && s[pos]>='a')
                    tmp[top++]=s[pos++];
                    else
                    {
                        //printf("%c",s[pos++]);
                        break;
                    }
                }
                tmp[top]='\0';

                if(top!=0)
                {
                    ans=tmp;

                    if(mp[ans]=="")cout<<ans;
                    else
                    {
                        cout<<mp[ans];
                    }
                }
                else
                printf("%c",s[pos++]);
            }
        }
        puts("");
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值