string dictionary order.txt

来自「1.表达式求值;2.二分匹配模板;3.最大流;4.点到线段的距离;5.字符串字典」· 文本 代码 · 共 31 行

TXT
31
字号
#include <stdio.h>
#include <stdlib.h>

struct dic {
   char eng[12], forn[12];
} d[100000];

int cnt = 0 , i,j,k;
char buf[10000];

compar(struct dic *a, struct dic *b) {
   return strcmp(a->forn, b->forn);
}

main(){
   while (gets(buf) && buf[0]) 	//读一行,gets
   {
      sscanf(buf,"%s %s",d[ cnt ].eng,d[ cnt ].forn);			//将buf分别读入到两个字符串中,空格分开!!!  好啊!!
      cnt++;
   }
   qsort(d, cnt ,sizeof(struct dic),(int (*) (const void *, const void *)) compar);		//字符串按字典顺序排序!!
   while ( gets(buf) ) 			//读到文件结束!!
   {
      struct dic b, *p;
      strcpy( b.forn, buf);
      p = bsearch(&b,d,cnt ,sizeof(struct dic),(int (*) (const void *, const void *)) compar);		//二分搜索!!!!
      if (p != NULL) printf("%s\n",p->eng);		
      else printf("eh\n");
   }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?