POJ2503 Babelfish(二分)
生活随笔
收集整理的這篇文章主要介紹了
POJ2503 Babelfish(二分)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目鏈接。
分析;
主要是學著用一下bsearch。
#include <stdio.h> #include <stdlib.h> #include <string.h>struct Entry{char english[15], foreign[15]; }entrys[100010];int cmp(const void *a, const void *b){return strcmp((*(struct Entry *)a).foreign, (*(struct Entry *)b).foreign); }int b_cmp(const void *a, const void *b){return strcmp((char *)a, (*(struct Entry *)b).foreign); }int main(){char s[30];int top=0;struct Entry *p;while(gets(s)){if(s[0] == '\0') break;sscanf(s, "%s %s", entrys[top].english, entrys[top].foreign);top++;}qsort(entrys, top, sizeof(entrys[0]), cmp);while(scanf("%s", s) == 1){p = (struct Entry *)bsearch(s, entrys, top, sizeof(entrys[0]), b_cmp);if(p == NULL){printf("eh\n");}else printf("%s\n", p->english);}return 0; } #include <stdio.h> #include <stdlib.h> #include <string.h>struct Entry{char english[15], foreign[15]; }entrys[100010];int cmp(const void *a, const void *b){return strcmp((*(struct Entry *)a).foreign, (*(struct Entry *)b).foreign); }int b_cmp(const void *a, const void *b){return strcmp((char *)a, (*(struct Entry *)b).foreign); }int main(){char s[30];int top=0;struct Entry *p;while(gets(s)){if(s[0] == '\0') break;sscanf(s, "%s %s", entrys[top].english, entrys[top].foreign);top++;}qsort(entrys, top, sizeof(entrys[0]), cmp);while(scanf("%s", s) == 1){p = (struct Entry *)bsearch(s, entrys, top, sizeof(entrys[0]), b_cmp);if(p == NULL){printf("eh\n");}else printf("%s\n", p->english);}return 0; }?
轉載于:https://www.cnblogs.com/tanhehe/archive/2013/04/07/3003758.html
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的POJ2503 Babelfish(二分)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 同态滤波与Retinex
- 下一篇: hadoop服务器的配置文件在哪,Had