poj 2503 Babelfish
2015-02-06 10:15
260 查看
原题:http://poj.org/problem?id=2503
简单的快排+二分搜索
具体实现如下:
简单的快排+二分搜索
具体实现如下:
#include <stdio.h> #include <stdlib.h> #include <string.h> #define N 1000000 + 10 typedef char State[11]; typedef struct tmp { State Eng; State Fori; }Node; Node rec ; int BinSearch(const char *target,int end) { int low=0,high=end,mid; while(low<=high) { mid=(low+high)>>1; if(0 == strcmp(rec[mid].Fori,target)) return mid; else if(-1 == strcmp(rec[mid].Fori,target)) low=mid+1; else high=mid-1; } return -1; } int cmp(const void *a,const void *b) { Node *p1=(Node *)a,*p2=(Node *)b; return strcmp(p1->Fori,p2->Fori); } void solve(char *buf,int count) { int index=BinSearch(buf,count); if(-1 == index) puts("eh"); else printf("%s\n",rec[index].Eng); } int main() { int count=0; State buf; while(gets(buf) && '\0'!=buf[0]) { State tp1,tp2; sscanf(buf,"%s %s",tp1,tp2); strcpy(rec[count].Eng,tp1); strcpy(rec[count++].Fori,tp2); } qsort(rec,count,sizeof(rec[0]),cmp); while(gets(buf)) solve(buf,count); return 0; }
相关文章推荐
- 【POJ】[2503]Babelfish
- POJ2503 Babelfish 二分 TWT Tokyo Olympic 1 COMBO-1
- poj 2503 Babelfish (trie)
- POJ 2503 Babelfish
- POJ 2503 Babelfish
- poj2503——Babelfish
- POJ 2503 Babelfish
- POJ 2503 Babelfish
- POJ 2503-Babelfish(STL-map)
- POJ2503————Babelfish
- poj 2503 Babelfish(字典树或STL水题) 解题报告(百炼2804)
- poj 2503 Babelfish(二分)
- 【POJ】2503 - Babelfish(STL)
- poj 2503 Babelfish
- poj 2503 Babelfish
- POJ 2503 Babelfish(STL、二分、字典树、哈希)
- POJ 2503 Babelfish(二分查找)
- POJ 2503 Babelfish
- POJ 2503 Babelfish(字典树水题)
- POJ 2503 Babelfish