📄 dic.txt
字号:
#include<iostream>
using namespace std;
struct dic
{
char bword[11];
char eword[11];
}*di;
struct point
{
struct dic *word;
struct point *left;
struct point *right;
};
void main()
{
struct point *head,*temp,*add;
char c[22];
char b[11],a[11];
int k=0,j=0,i=0,len=0,z=0;
for(;;)
{
cin.getline(c,22);
len=strlen(c);
if(len==0)
break;
for(i=0;i<len;i++)
{
if(c[i]==' ')
break;
}
for(j=0;j<i;j++)
{
a[j]=c[j];
}
a[j]='\0';
for(j=0;j<len-1-i;j++)
{
b[j]=c[i+1+j];
}
b[j]='\0';
j=0;
di=new struct dic;
strcpy(di->eword,a);
strcpy(di->bword,b);
if(z==0)
{
head=new struct point;
head->word=di;
head->left=NULL;
head->right=NULL;
temp=head;
z=1;
continue;
}
do
{
if((strcmp(b,temp->word->bword)<0)&&(temp->left==NULL))
{
add=new struct point;
add->word=di;
add->left=NULL;
add->right=NULL;
temp->left=add;
temp=head;
break;
}
if((strcmp(b,temp->word->bword)>0)&&(temp->right==NULL))
{
add=new struct point;
add->word=di;
add->left=NULL;
add->right=NULL;
temp->right=add;
temp=head;
break;
}
if((strcmp(b,temp->word->bword)<0)&&(temp->left!=NULL))
{
temp=temp->left;
continue;
}
if((strcmp(b,temp->word->bword)>0)&&(temp->right!=NULL))
{
temp=temp->right;
continue;
}
if(strcmp(b,temp->word->bword)==0)
{
temp=head;
break;
}
}while(k==0);
}
temp=head;
while(cin>>b)
{
do
{
if((strcmp(b,temp->word->bword)<0)&&(temp->left==NULL))
{
cout<<"eh"<<endl;
temp=head;
break;
}
if((strcmp(b,temp->word->bword)>0)&&(temp->right==NULL))
{
cout<<"eh"<<endl;
temp=head;
break;
}
if((strcmp(b,temp->word->bword)<0)&&(temp->left!=NULL))
{
temp=temp->left;
continue;
}
if((strcmp(b,temp->word->bword)>0)&&(temp->right!=NULL))
{
temp=temp->right;
continue;
}
if(strcmp(b,temp->word->bword)==0)
{
cout<<temp->word->eword<<endl;
temp=head;
break;
}
}while(k==0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -