poj 2503 Babelfish
2012-06-06 10:36
288 查看
还是字典树的水题一道,输入的方法让我觉得很神奇.........我是菜,输入都搞不好....
#include <set> #include <map> #include <ctime> #include <queue> #include <cmath> #include <stack> #include <limits> #include <vector> #include <bitset> #include <string> #include <cstdio> #include <cstring> #include <fstream> #include <string.h> #include <iostream> #include <algorithm> #define Si set<int> #define LL long long #define pb push_back #define PS printf(" ") #define Vi vector<int> #define LN printf("\n") #define lson l,m,rt << 1 #define rson m+1,r,rt<<1|1 #define SD(a) scanf("%d",&a) #define PD(a) printf("%d\n",a) #define SET(a,b) memset(a,b,sizeof(a)) #define FF(i,a) for(int i(0);i<(a);i++) #define FD(i,a) for(int i(a);i>=(1);i--) #define FOR(i,a,b) for(int i(a);i<=(b);i++) #define FOD(i,a,b) for(int i(a);i>=(b);i--) #define readf freopen("input.txt","r",stdin) #define writef freopen("output.txt","w",stdout) const int maxn = 301; const int INF = ~0U>>1; const int dx[]={0,1,0,-1}; const int dy[]={1,0,-1,0}; const double pi = acos(-1.0); using namespace std; char a[100001][11],tmp,ss[11]; class tire{ public: int id; tire *next[26]; tire(){ id=-1; SET(next,0); } }root; void insert(char *word,int ord){ tire *p=&root; int k=0; int t; while(word[k]!='\0'){ t=word[k]-'a'; if(!p->next[t]) p->next[t]=new tire; p=p->next[t]; k++; } p->id=ord; } int query(char *word){ tire *p=&root; int k=0; int t; while(word[k]){ t=word[k]-'a'; if(!p->next[t]) return -1; p=p->next[t]; k++; } return p->id; } int main() { int cnt=0; while(true){ tmp=getchar(); //这种输入的方法对我来说还是很陌生的............. if(tmp=='\n') break; scanf("%s%s",a[cnt]+1,ss); a[cnt][0]=tmp; insert(ss,cnt); cnt++; tmp=getchar(); } int ans; while(~scanf("%s",ss)){ ans=query(ss); if(ans==-1) puts("eh"); else printf("%s\n",a[ans]); } return 0; }
相关文章推荐
- POJ 2503 Babelfish(map,字典树,快排+二分,hash)
- POJ 2503 Babelfish
- POJ-2503 Babelfish 解题报告
- poj 2503.Babelfish
- Babelfish(poj 2503)
- Poj 2503 Babelfish
- POJ 2503 Babelfish (字典树)
- POJ_2503_Babelfish【字典树】
- poj 2503 babelfish
- 【POJ】2503 - Babelfish(STL)
- POJ - 2503 Babelfish
- poj_2503_Babelfish(字典树&&map)
- 【POJ 2503】Babelfish(字符串)
- poj 2503 Babelfish(字典树或着STL)
- [ACM] [算法基础] POJ 2503 在线翻译Babelfish(二分查找 字符串)
- POJ 2503 Babelfish(hash + map)
- poj 2503 Babelfish
- POJ2503-Babelfish
- poj 2503 Babelfish
- POJ 2503 Babelfish