trie:141MS
#include<cstdio> const int maxn=100000+10; const int tk=26,tb=97; int triecnt=1,bufcnt=0,tree[maxn<<2][tk+1]; char buf[maxn<<1][12]; int search(char *s) { for(int rt=0;rt=tree[rt][*s-tb];) if(*(++s)==0) return tree[rt][tk]; return 0; } void insert(char *s,int rank=1) { int rt,nxt; for(rt=0;*s;rt=nxt,++s) { nxt=tree[rt][*s-tb]; if(!nxt) tree[rt][*s-tb]=nxt=triecnt++; } tree[rt][tk]=rank; } int main() { int i,j; char str[50]; while(gets(str)&&str[0]) { char *s1=buf[bufcnt],*s2=buf[bufcnt+1]; for(i=0;str[i]!=' ';i++) s1[i]=str[i]; s1[i]=0; while(str[++i]==' '); for(j=0;str[i];i++) s2[j++]=str[i]; s2[j]=0; insert(s2,bufcnt+1); bufcnt+=2; } while(gets(str)!=NULL) { int t=search(str); puts(t?buf[t-1]:"eh"); } return 0; }
您还没有登录,请您登录后再发表评论
北大POJ2503-Babelfish 解题报告+AC代码
NULL 博文链接:https://128kj.iteye.com/blog/1734586
C语言 poj npu 西工大 C语言Poj答案全完整打包,给有需要的朋友
北大POJ2525-Text Formalization【TrieTree】 解题报告+AC代码+测试数据 http://hi.csdn.net/!s/XW4FQ3
北大POJ2513-Colored Sticks【TrieTree+MergeSet+EulerPath】 解题报告+AC代码
POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类
poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题...
LeetCode判断字符串是否循环 :bookmark_tabs:Plan 动态规划 背包问题 动态规划 POJ 3267 POJ 1260 POJ ...POJ ...POJ ...POJ ...POJ ...POJ ...POJ ...POJ ...POJ ...POJ ...POJ ...POJ ...POJ ...POJ ...POJ ...POJ ...POJ ...POJ ...POJ ...trie树 POJ 251
POJ第1861题源码 POJ第1861题源码 POJ第1861题源码
动态规划讲解文档,比较基础,浅显易懂。 大牛请绕道~
北大POJ1159-Palindrome 解题报告+AC代码
poj 3414解题报告poj 3414解题报告poj 3414解题报告poj 3414解题报告
poj分类poj分类poj分类poj分类
北大POJ2002-Squares 解题报告+AC代码
poj 1012解题报告poj 1012解题报告poj 1012解题报告poj 1012解题报告
POJ1503解答 POJ1503解答,正确答案(已通过POJ)
poj 2329解题报告poj 2329解题报告poj 2329解题报告poj 2329解题报告
POJ1048,加强版的约瑟夫问题 难度中等
poj 1659解题报告poj 1659解题报告poj 1659解题报告poj 1659解题报告
POJ1083的代码,POJ1083的代码,POJ1083的代码
相关推荐
北大POJ2503-Babelfish 解题报告+AC代码
NULL 博文链接:https://128kj.iteye.com/blog/1734586
C语言 poj npu 西工大 C语言Poj答案全完整打包,给有需要的朋友
北大POJ2525-Text Formalization【TrieTree】 解题报告+AC代码+测试数据 http://hi.csdn.net/!s/XW4FQ3
北大POJ2513-Colored Sticks【TrieTree+MergeSet+EulerPath】 解题报告+AC代码
POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类
poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题...
LeetCode判断字符串是否循环 :bookmark_tabs:Plan 动态规划 背包问题 动态规划 POJ 3267 POJ 1260 POJ ...POJ ...POJ ...POJ ...POJ ...POJ ...POJ ...POJ ...POJ ...POJ ...POJ ...POJ ...POJ ...POJ ...POJ ...POJ ...POJ ...POJ ...POJ ...trie树 POJ 251
POJ第1861题源码 POJ第1861题源码 POJ第1861题源码
动态规划讲解文档,比较基础,浅显易懂。 大牛请绕道~
北大POJ1159-Palindrome 解题报告+AC代码
poj 3414解题报告poj 3414解题报告poj 3414解题报告poj 3414解题报告
poj分类poj分类poj分类poj分类
北大POJ2002-Squares 解题报告+AC代码
poj 1012解题报告poj 1012解题报告poj 1012解题报告poj 1012解题报告
POJ1503解答 POJ1503解答,正确答案(已通过POJ)
poj 2329解题报告poj 2329解题报告poj 2329解题报告poj 2329解题报告
POJ1048,加强版的约瑟夫问题 难度中等
poj 1659解题报告poj 1659解题报告poj 1659解题报告poj 1659解题报告
POJ1083的代码,POJ1083的代码,POJ1083的代码