简单的电子词典 因手机问题未图

01./*                 
02.*Copyright (c) 2014,烟台大学计算机学院                 
03.*All rights reserved.                 
04.*文件名称: test.cpp                 
05.*作 者:李晓凡                 
06.*完成日期:2014年11月28日                 
07.*版本号:v1.0                 
08.*                 
09.*问题描述:  做一个简单的电子词典
10.*输入描述: 所需查找单词
11.*程序输出:  汉语意思
12.*/
#include<iostream>
#include<string>
#include<fstream>
#include<cstdlib>
using namespace std;
int found(int a,string word);
string e[8000];
string c[8000];
int main()
{
	int i,n,index;
	string eword;
	ifstream infile ("dictionary.txt",ios::in);
	if (!infile)
	{
		cerr<<"open error!"<<endl;
		exit(1);
	}
	for (i=0;i<8000;i++)
	{
		infile>>e[i];
		infile>>c[i];
	}
	infile.close();
	n=i;
	while (eword!="0000")
	{
		cout<<"请输入要查寻的英语单词 0000结束"<<endl;
		cin>>eword;
		if (eword=="0000")
		{
		cout<<"谢谢使用";break;
		}
		else 
		{
			index=found(n,eword);
			if (index==0)
	cout<<"未找到您要查询的单词"<<endl;
			else 
			cout<<e[index]<<"的汉语意思是 :"<<c[index]<<endl;
		}
	}
		return 0;
}
int found(int high,string word)
{
	int low=0,mid;
	while (low<=high)
	{
		mid=(low+high)/2;
		if (word==e[mid])
		{
		return mid;
		break;
		}
		else 
		{
			if (word>e[mid])
			low=mid+1;
		    else
		    high=mid-1;
		}
	}
		return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值