Dictionary
来源:互联网 发布:算法 epub 编辑:程序博客网 时间:2024/04/28 17:50
#include <fstream> #include <iostream> #include <string> using namespace std; class Word //定义类Word{ public: void set(string E,string C,string Wor); //置值 int compare(string); void display(); //输出private: string English; string Chinese; string Word_Class; }; void Word::set(string E, string C, string Wor) { English=E; Chinese=C; Word_Class=Wor; } int Word::compare(string k) { return English.compare (k); } void Word::display() { cout<<English<<'\t'<<Word_Class<<'\t'<<Chinese<<endl; cout<<endl; } int BinSeareh(int low, int high, Word *w, string k) { int mid; while(low<=high) { mid=(low+high)/2; if(w[mid].compare(k)==0) { return mid; } if(w[mid].compare(k)>0) { high=mid-1; } else low=mid+1; } return -1; } int main() { Word words[8000]; string E,C,W_C; string key;//查询关键字 int wordsNum=0; ifstream infile("dictionary.txt",ios::in); if(!infile) { cerr<<"open error!"<<endl; exit(1); } while(!infile.eof()) { infile>>E>>C>>W_C; words[wordsNum].set(E,C,W_C); ++wordsNum; } do { cout<<"请输入要查询的词:"; cin>>key; if(key!="0000") { int low=0,high=wordsNum-1; int index=BinSeareh(low, high, words,key); if(index==-1) cout<<"查无此词!"<<endl; else words[index].display(); } } while(key!="0000"); cout<<"欢迎下次使用!"<<endl; system("pause"); return 0; }
运行结果:
请输入要查询的词:what
what pron. 什么
请输入要查询的词:is
查无此词!
请输入要查询的词:was
查无此词!
请输入要查询的词:this
this adj.,pron. 这,这个
请输入要查询的词:that
that adj. 那,那个
请输入要查询的词:where
where adv. 哪里
请输入要查询的词:come
come v. 来到,出现,发生
请输入要查询的词:a
查无此词!
请输入要查询的词:
感言:
相当的好(但别人指点了不少)!!!还要努力啊!!!
- Dictionary
- dictionary
- Dictionary
- Dictionary
- dictionary
- Dictionary
- Dictionary
- dictionary
- Dictionary
- Dictionary
- Dictionary
- Dictionary
- Dictionary I
- java dictionary
- scripting.dictionary
- Dictionary 泛型类
- ABAP Dictionary
- online dictionary
- jQuery表格隔行样式-(含鼠标停留行样式)
- QString::arg() 函数
- Android 4.0 audio
- The LocalSystem Account
- 八个移动产品设计必备网站
- Dictionary
- 主题:如何学习Hibernate
- android获取web服务器端session并验证登陆
- 内存管理与“三地址”的千丝万缕(1)
- linux内核分析———SLAB原理及实现
- Ant编译Enum类型的错误
- oracle 聚合函数
- httpclient超时总结
- 长沙现代阳光体检中心