第14周项目4 英汉词典

来源:互联网 发布:网络歌曲么么哒 编辑:程序博客网 时间:2024/05/17 07:44
/*      *Copyright (c)2014,烟台大学计算机与控制工程学院      *All rights reserved.      *文件名称:gcd.cpp      *作    者:惠睿      *完成日期:2014年11月30日      *版 本 号:v1.0      *      *问题描述:输入英文词汇,输出汉语意思。*程序输出:输出成绩单。*/#include <fstream>#include<iostream>#include<cstdlib>#include<string>using namespace std;string e[8000],c[8000];int wordsNum=0;int BinSeareh(int low, int high, string k);int main( ){ string key;ifstream infile("dictionary.txt",ios::in);if(!infile){cerr<<"open error!"<<endl;exit(1);}while (infile>>e[wordsNum]>>c[wordsNum]){++wordsNum;}infile.close();do{cout<<"请输入要查的词(0000结束):";cin>>key;if (key=="0000")break;else{int low=0,high=wordsNum-1;int index=BinSeareh(low, high, key);if (index == -1)cout<<"查无此词!"<<endl<<endl;elsecout<<key<<"的中文意思是:"<<c[index]<<endl<<endl;}}while(1);cout<<"欢迎再次使用!"<<endl<<endl;return 0;}int BinSeareh(int low, int high, string k){int mid;while(low<=high){mid=(low + high) / 2;if(e[mid]==k){return mid;}if(e[mid]>k)high=mid-1;elselow=mid+1;}return -1;}


运行结果:

学习心得:好麻烦的程序!

 

0 0