第17周项目7-电子词典结构体版
来源:互联网 发布:软件开发需要几个人 编辑:程序博客网 时间:2024/06/06 02:18
问题及代码:
/* *Copyright(c)2014,烟台大学计算机学院 *Allrights reserved. *文件名称:MADE88.cpp *作 者:孙化龙 *完成日期:2014年12月23日 *版 本 号:v1.0 * *问题描述:做一个简单的电子词典*/#include <iostream>#include <fstream>#include <cstdlib>#include <cstring>using namespace std;struct Word{ string english; string chinese; string wordclass;};int main(){ Word words[8000]; int i,wordsNum=0; ifstream infile("dictionary.txt",ios::in); //以输入的方式打开文件 if(!infile) //测试是否成功打开 { cerr<<"open error!"<<endl; exit(1); } i=0; while(infile>>words[i].english>>words[i].chinese>>words[i].wordclass) { ++wordsNum; ++i; } infile.close(); string key="a"; while(key!="0000") { cout<<"输入要查找的词(0000退出):"; cin>>key; int low=0,high=wordsNum-1,mid; while(low<=high) { mid=(low+high)/2; if(words[mid].english==key) { cout<<words[mid].english<<"<---"<<words[mid].wordclass<<words[mid].chinese<<endl; break; } else if(words[mid].english>key) high=mid-1; else if(words[mid].english<key) low=mid+1; } if(low>high&&key!="0000") cout<<"查无此词"<<endl; } return 0;}
运行结果:
0 0
- 第17周项目7-电子词典结构体版
- 第17周项目7-电子词典结构体版
- 第17周项目7 电子词典结构体版
- 第17周项目7-电子词典结构体版
- 第17周项目7-电子词典结构体版
- 第17周项目7--电子词典结构体版
- 第17周项目电子词典结构体版
- 第17周 项目7 结构体电子词典
- 2014秋C++第17周 项目7参考 电子词典结构体版
- 第17周上机实践项目7——电子词典结构体版
- 第十七周项目电子词典结构体版
- 第十七周项目7-电子词典结构体版
- 第十七周 项目7 电子词典结构体版
- 第十七周 【项目7-电子词典结构体版】
- 第十七周项目 7 电子词典结构体版
- 第十七周项目7-电子词典结构体版
- 第十七周项目7 电子词典结构体版
- 第十七周 项目七:电子词典结构体版
- 网络图片下载并保存本地
- leetcode 125-Valid Palindrome
- 九九乘法表
- nginx监听一个端口多域名转发配置
- IOS调试技巧:当程序崩溃的时候怎么办 iphone IOS
- 第17周项目7-电子词典结构体版
- uva 10392 Factoring Large Numbers
- 开源框架:iConsole
- Windows 2000 资源工具包中
- IOS调试技巧:当程序崩溃的时候怎么办 iphone IOS
- Unity利用Resources加载资源
- PHP变量的两种定界符
- 主程的晋升攻略(8):数据层的演进(上)
- 第十六周项目一数组的排序