第十七周项目7-电子词典结构体版
来源:互联网 发布:必备的办公软件 编辑:程序博客网 时间:2024/06/06 10:46
/** Copyright (c) 2014, 烟台大学计算机学院* All rights reserved.* 文件名称:Project4.cpp* 作 者:冷基栋* 完成日期:2014年12月23日* 版 本 号:v1.0* 问题描述:做一个简单的电子词典。在文件dictionary.txt中,保存的是英汉对照的一个词典,词汇量近8000个, 英文与释义间用’\t’隔开。编程序,将文件中的内容读到两个数组e[]和c[]中,分别代表英文和中文, 由用户输入英文词,显示中文意思。运行程序后,支持用户连续地查词典,直到输入“0000”结束, 提示:文件中的词汇已经排序,故在查找时,用二分查找法提高效率。* 输入描述:单词* 程序输出:中文意思*/#include <iostream>#include <fstream>#include <cstdlib>#include <string>using namespace std;struct Word{ string english; string word_class; string chinese;};Word words[8000];int wordsNum=0;int wsearch(int low,int high,string k);int main(){ string key; ifstream infile("dictionary.txt",ios::in); if(!infile) { cerr<<"open error!"; exit(1); } while(wordsNum<=8000) { infile>>words[wordsNum].english; infile>>words[wordsNum].chinese; infile>>words[wordsNum].word_class; wordsNum++; } infile.close(); do { cout<<"请输入待查询的关键词(英文),0000结束:"<<endl; cin>>key; if(key=="0000") break; else { int low=0,high=wordsNum-1; int index=wsearch(low,high,key); if(index==-1) cout<<"查无此词!"<<endl; else cout<<key<<"—>"<<words[index].word_class<<"\t"<<words[index].chinese<<endl<<endl; } }while(-1); cout<<"欢迎再次使用!"<<endl; return 0;}int wsearch(int low,int high,string k){ int mid; while(low<=high) { mid=(low+high)/2; if(words[mid].english==k) return mid; if(words[mid].english>k) high=mid-1; else low=mid+1; } return -1;}
0 0
- 第十七周项目电子词典结构体版
- 第十七周项目7-电子词典结构体版
- 第十七周 项目7 电子词典结构体版
- 第十七周 【项目7-电子词典结构体版】
- 第十七周项目 7 电子词典结构体版
- 第十七周项目7-电子词典结构体版
- 第十七周项目7 电子词典结构体版
- 第十七周 项目七:电子词典结构体版
- 第十七周项目7:电子词典-参考答案
- 第17周项目7-电子词典结构体版
- 第17周项目7-电子词典结构体版
- 第17周项目7 电子词典结构体版
- 第17周项目7-电子词典结构体版
- 第17周项目7-电子词典结构体版
- 第17周项目7--电子词典结构体版
- 第十七周项目7 电子词典(还有疑问,求解答)
- 第十七周项目七—电子词典
- 第17周项目电子词典结构体版
- IOS中定时器NSTimer的开启与关闭
- Android快速开发系列 10个常用工具类
- J2EE、J2SE、J2ME是什么意思?
- 一篇很全面的freemarker教程
- centOS+bochs+gdb调试linux0.11
- 第十七周项目7-电子词典结构体版
- rake 是什么
- Android 关于videoview 弹窗 “抱歉,无法播放此视频”
- 蓝桥杯试题集 基础练习 回文数
- Unix C (十)
- javascript跨框架显示div
- ios:UIAlertView自动消失
- Unity碰撞检测
- CHM 已取消到该网页的导航