oop판 전자 사전 만들기 (확장 1)

2243 단어
/*           
*All right reserved.
*    :   oop      ((  1)
*  :  
*    :2014 6 2 
*   :v1.0
*             :   oop      (  1)
*    :*/
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <fstream>
#include <cstring>
using namespace std;
class Word
{
private:
    string english;
    string word_class;
    string chinese;
public:
    friend istream& operator >>(istream &input,Word &t);
    friend ostream& operator <<(ostream &output,Word &t);
    string fanhui()
    {
        return english;
    }
    void dispay()
    {
        cout<<chinese<<"  ";
    };
};
istream& operator >>(istream &input,Word &t)
{
    input>>t.english>>t.chinese>>t.word_class;
    return input;
}
int main()
{
    string n;
    Word word[8000];
    int m;
    cout<<"               !!!"<<endl;
    cin>>m;
    string word1[m];
    int num=0,low,mid,high;
    cout<<"     "<<endl;
    ifstream infile("dic.txt",ios::in);
    if(!infile)
    {
        cerr<<"data error!!!"<<endl;
        exit(1);
    }
    while(!infile.eof())
    {
        infile>>word[num];
        num++;
    }
    infile.close();
      int w=0;
     while(cin>>word1[w])
     {
        if(word1[w]=="1111")
        {
            break;
        }
        else
        {
            high=num;
            low=0;
            mid=(high+low)/2;
            while(low<high&&word[mid].fanhui()!=word1[w])
            {
                if(word[mid].fanhui()<word1[w])
                {
                    low=mid+1;
                }
                if(word[mid].fanhui()>word1[w])
                {
                    high=mid-1;
                }
                mid=(high+low)/2;
            }
            if(word[mid].fanhui()!=word1[w])
            {
                cout<<"    !"<<endl;
            }
            else
            {
                 word[mid].dispay();
            }
          }
          w++;
       cout<<"(     1111)"<<endl;
     }
    return 0;
}

좋은 웹페이지 즐겨찾기