标签:trie树
字典树
看题库上说这是字典树,不过被我水过去了。
题意是说用对应的字典,翻译出火星文。
each line will contain at most 3000 characters.
看到这句话我就安心了。Time Limit: 10000/5000 MS (Java/Others)
果断用map 来水了。还真AC了。3296MS 。本来是想巩固一下字典树的,不过……。
#include<cstdio> #include<cstring> #include<string> #include<queue> #include<algorithm> #include<queue> #include<map> #include<stack> #include<iostream> #include<list> #include<set> #include<cmath> #define INF 0x7fffffff #define eps 1e-6 using namespace std; map<string,string>word; int main() { string a,b; word.clear(); while(cin>>a,a!="START"); while(cin>>a,a!="END") { cin>>b; word[b]=a; } while(cin>>a,a!="START"); char str[3001]; gets(str); while(gets(str)) { if(strcmp(str,"END")==0)return 0; int len=strlen(str); char s[3001],j=0; for(int i=0;i<len;i++) { if(str[i]>='a'&&str[i]<='z') s[j++]=str[i]; else { s[j]='\0';j=0; b=s; if(word.find(b)==word.end()) cout<<b; else cout<<word[b]; printf("%c",str[i]); } } printf("\n"); } }
HDU 1075 What Are You Talking About,布布扣,bubuko.com
HDU 1075 What Are You Talking About
标签:trie树
原文地址:http://blog.csdn.net/dongshimou/article/details/37510045