HDU1075 What Are You Talking About(map)

传送门

题目大意:一个单词对应另一个单词 翻译一段文字

题解:stl map走一波

代码:

#include
#include
#include
#include
#include
using namespace std;

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

char a[3010],b[3010];

string s;
 
int main()
{
    scanf("%s",a);
    while(1)
    {
        scanf("%s",a);
        if(strcmp(a,"END")==0) break;
        scanf("%s",b);
        m[b]=a;
    }
    scanf("%s",a);getchar();
    while(1)
    {
        getline(cin,s);
        if(s.compare("END")==0) break;
        int len=s.length();
        for(int i=0;i)
        {
            if(s[i]>='A'&&s[i]<='Z'||s[i]>='a'&&s[i]<='z')
            {
                int t=0;
                for(;i)
                {
                    if(!(s[i]>='A'&&s[i]<='Z'||s[i]>='a'&&s[i]<='z')) break;
                    a[t++]=s[i];
                }
                a[t]='\0';
                it=m.find(a);
                if(it!=m.end()) cout<second;
                else printf("%s",a); 
            }
            printf("%c",s[i]);
        }
        printf("\n"); 
    }
    return 0;
}

 

你可能感兴趣的:(HDU1075 What Are You Talking About(map))