词典(没写完)

#include<iostream>   
#include<string> 
string e[8000],c[8000];   
int  cijian(int low, int high, string k);  
using namespace std;  
int main( )  
{  
    string key;    
    ifstream infile("词典.txt",ios::in);   
    if(!infile)       
    {  
        cerr<<"open error!"<<endl;  
        exit(1);  
    }  
    while (!infile.eof())  
    {  
        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;  
            else  
                cout<<key<<"的中文意思是:"<<c[index]<<endl<<endl;  
        }  
    }  
    while(1);  
    cout<<"欢迎再次使用!"<<endl<<endl;  
    return 0;  





	int  cijian(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;   
        else  
            low=mid+1;  
    }  
    return -1;   
}  



你可能感兴趣的:(词典(没写完))