第14周项目4-电子词典
来源:互联网 发布:韩顺平 linux视频教程 编辑:程序博客网 时间:2024/05/19 02:18
/**Copyright (c) 2014,烟台大学计算机学院*All rights reserved.*文件名称:Annpion.cpp*作者:王耀鹏*完成日期:2014年12月1日*版本号:v1.0**问题描述:电子词典。*输入描述:文件输入词库,输入要查找的词。*程序输出:输出查找词的中文意思*/#include<iostream>#include<fstream>#include<cstdlib>#include<string>using namespace std;string word,e[10000],c[10000];int midsearch(int low,int high,string word);int main(){ int i=0; ifstream infile("dictionary.txt",ios::in); if(!infile) { cerr<<"open error!"<<endl; exit(1); } while(infile>>e[i]>>c[i]) { i++; } infile.close(); do { cout<<"请输入要查找的词(0000结束):"; cin>>word; if(word=="0000") break; else { int low=0,high=i-1; int bin=midsearch(low,high,word); if(bin==-1) cout<<"查无此词"<<endl<<endl; else cout<<word<<"的中文意思是"<<c[bin]<<endl<<endl; } } while(word!="0000"); return 0;}int midsearch(int low,int high,string word){ int mid; while(low<=high) { mid=(low+high)/2; if(e[mid]==word) return mid; if(e[mid]>word) high=mid-1; else low=mid+1; } return -1;}
运行结果:
0 0
- 第14周项目4-电子词典
- 第14周项目4-电子词典
- 第14周项目 4电子词典
- 第14周项目4-电子词典
- 第14周项目4-电子词典
- 第14周 项目4-电子词典
- 第14周项目4-电子词典
- 第14周项目4电子词典
- 第14周项目4电子词典
- 第14周项目4-电子词典
- 第14周 项目4 电子词典
- 第14周项目4-电子词典
- 第14周项目4-电子词典
- 2014秋C++第14周项目4参考-电子词典
- 第14周上机实践项目4——电子词典
- 第14周项目4-电子词典(二分法查找)
- 第14周上机实践项目3——电子词典
- 第14周 项目三-OOP版电子词典
- 第12周项目 3.2 递归求解 1,3,5,7,9,,,
- google hosts list
- IOS开发/iphone开发震动与播放声音
- javascript 常用的时间函数
- mvc中的 @Styles @Scripts 上下文找不到
- 第14周项目4-电子词典
- oracle中execute immediate用法
- android_baiduMap(二) ---- 编码注意事项
- 2013年十大即时聊天App年鉴
- 杂文:该隐
- JavaScript for...in 语句
- Shuriken粒子系统学习笔记
- 第12周项目 3.3 递归 两个数的最大公约数
- HDU3790 最短路径问题 Dijkstra算法