poj2503Babelfish
来源:互联网 发布:python做app 编辑:程序博客网 时间:2024/05/22 12:07
#include <iostream>#include <cstring>#include <cstdio>#include <cstdlib>using namespace std;const int N=200005;//空间开大了int chd[N][26];//存储节点编号char v[N][26];//串尾节点标记//对于map<string,int>为int v[][]int ID[128];//每个字母的IDint sz;//节点数void init(){ memset(chd, 0, sizeof(chd)); memset(v, 0, sizeof(v)); sz= 1; for (int i = 0; i < 26; i++) ID[i + 'a'] = i;}void insert(char *s,char *w){//as map<string string> int cur=1; for(int i=0;s[i];++i){ if(!chd[cur][ID[s[i]]]) chd[cur][ID[s[i]]]=++sz; cur=chd[cur][ID[s[i]]]; } strcpy(v[cur],w);}/*相当于map<string,int>void insert(char *s, intw) {intcur = 1;for (inti= 0; s[i]; i++) {if (!chd[cur][ID[s[i]]])chd[cur][ID[s[i]]] = ++sz;cur = chd[cur][ID[s[i]]];}v[cur] = w;}*/int query(char *s){ int cur=1; for(int i=0;s[i];++i){ if(!chd[cur][ID[s[i]]]) return -1; cur=chd[cur][ID[s[i]]]; } return cur;}int main(){ char a[30],b[30],tmp[30]; init(); while(gets(tmp)&&tmp[0]!='\0'){//读入问题,才发现基础差的要命 sscanf(tmp,"%s %s",a,b); insert(b,a);//////////////////////////////////////////////////the foreign string is the key } while(scanf(" %s",tmp)==1){ int k=query(tmp); if(k==-1) printf("eh\n"); else printf("%s\n",v[k]); } return 0;}
0 0
- poj2503Babelfish
- poj2503Babelfish
- poj2503Babelfish
- poj2503Babelfish(hash);
- poj2503Babelfish字典树
- POJ2503Babelfish(MAP+字典树)
- poj2503Babelfish(Trie tree 或者map)
- 给自己的requestProxy写个教程
- ios--UITabBar的基本概念
- vector中erase用法注意事项
- UVA 10061 How many zero's and how many digits ?(数论)
- hdu1845Jimmy’s Assignment
- poj2503Babelfish
- 计算1-1/x+1/x*x
- 04-4. 猜数字游戏(15)
- 黑马程序员——网络编程
- hdu 1028 Ignatius and the Princess III
- 友元类
- codeforces 258B Little Elephant and Elections 数位DP+排列组合
- 【九度OJ】1014【快速排序】
- C/C++ sort函数的用法