/*
*
* Copyright (c)2014,
* All rightsreserved.
* : fibnacci.cpp
* :
* :2014 6 5
* : v1.0
*
* :
* :
* :
* :
*/
#include <iostream>
#include <cstring>
#include <fstream>
using namespace std;
class Word
{
private:
string english;
string chinese;
string word_class;
public:
void getword(string e,string c,string w)
{
english=e,chinese=c,word_class=w;
}
void dispaly()
{
cout<<english<<'\t'<<chinese<<'\t'<<word_class<<endl;
}
bool dengyu(string &w)
{
bool f=false;
if(w==english)
{
f=true;
}
return f;
}
bool dayu(string &w)
{
bool f=false;
if(w>english)
{
f=true;
}
return f;
}
};
class Dictionary
{
private:
int wordsNum;
Word words[8000];
public:
Dictionary()
{
int i=0;
string e,c,w;
ifstream infile("dictionary.txt");
if(!infile)
{
cout<<" !"<<endl;
}
while(infile>>e>>c>>w)
{
words[i].getword(e,c,w);
i++;
}
wordsNum=i-1;
}
void fin(string w)
{
int mi=0,mid=wordsNum/2,ma=wordsNum;
while(1)
{
if(words[mid].dengyu(w))
{
words[mid].dispaly();
break;
}
else
{
if(words[mid].dayu(w))
{
mi=mid+1;
mid=(wordsNum+mi)/2;
}
else
{
ma=mid-1;
mid=(ma+mi)/2;
}
}
if(mi>ma)
{
cout<<" !"<<endl;
break;
}
}
}
};
int main()
{
string word;
Dictionary dictionary;
ifstream infile("aboutcpp.txt");
if(!infile)
{
cout<<" !"<<endl;
}
while(infile>>word)
{
cout<<word<<"--------";
if((word>"@"&&word<"[")||(word>"`"&&word<"{"))
dictionary.fin(word);
}
return 0;
}