软件工程报告3查字典
来源:互联网 发布:拟制血亲 知乎 编辑:程序博客网 时间:2024/04/29 08:43
#include<stdio.h>#include<string.h>#include<stdlib.h>char e[8000][20],c[8000][20]; //英文和中文数组,从文件中读入int wordsNum=0; //词库中实际存在的词汇条数int BinSeareh(int low, int high, char *k);int main( ){ char key[20]; //查询关键词 FILE *fp; fp = fopen("dictionary.txt","r"); //以输入的方式打开文件 if(fp==NULL) //测试是否成功打开 { printf("open error!\n"); exit(1); } while(!feof(fp)) //读取成功,则重复从文件中读//while(!feof(fp)) 的意思是若文件读取未结束;一直运行下去//直到最后一个单词 { fscanf(fp, "%s%s", e[wordsNum], c[wordsNum]);//将读入的字符写入目标文件; ++wordsNum;//计算文件中真正的单词数目 } fclose(fp); //输入待查关键词并用二分查找法进行查询 do { printf("请输入要查的词(0000结束):"); scanf("%s", key); if (strcmp(key,"0000")==0)//0000应该加上双引号,否则想结束运行时,不能停止,会认为输入的是一个单词000 break; else { int low=0,high=wordsNum-1;
int index=BinSeareh(low, high, key); if (index == -1) printf("在词库中未找到此词!\n\n"); else printf("%s 的中文意思是:%s\n\n", key, c[index]); } } while(1);}//二分查找,结果为所查词在数组中的下标,二分法的效率高int BinSeareh(int low, int high, char *k){ int mid; int index=-1; while(low<=high) { mid=(low + high) / 2; if(strcmp(e[mid],k)==0) { index=mid; //查找成功返回、 break; } if(strcmp(e[mid],k)>0) high=mid-1; //继续在e[low..mid-1]中查找 else low=mid+1; //继续在e[mid+1..high]中查找 } return index; //当low>high时表示查找区间为空,查找失败}
0 0
- 软件工程报告3查字典
- 查字典
- 查字典
- 软件工程(3)智能手环市场调研报告
- 软件工程实验报告一
- 软件工程导论实验报告
- 软件工程实验报告一
- 软件工程实验报告 一
- 软件工程实验报告二
- 软件工程实验报告 二
- 软件工程实验报告 三
- 软件工程实验报告 二
- 软件工程实验报告 一
- 软件工程实验报告 一
- 软件工程实验报告 三
- 软件工程实验报告 三
- 软件工程实验报告三
- 查字典问题
- git clone 时出现的ssl证书问题
- android自带Base64编码
- Fragment生命周期
- vmrun命令行的使用(VMWare虚拟机)
- 物联管家PDA 无缝对接网店管家云端 电商erp 实现电商条码无线仓储
- 软件工程报告3查字典
- mysql内存超出 mysqld: Out of memory 解决办法
- SQL 查询数据库占用CPU过高问题脚本
- 使用smartupload组件实现jsp+jdbc上传下载文件
- 模型分类
- restore 数据文件到新路径
- Unity2D:Sprite和UI Image的区别
- 栈结构应用的两个实例
- 课程设计<3>---电子词典