當前位置:成語大全網 - 書法字典 - c並行詞典

c並行詞典

# include & ltstdio.h & gt

# include & ltstring.h & gt

# include & ltmalloc.h & gt

# include & ltmath.h & gt

#定義min(A,B)(A & lt;b?答:乙)

#定義max(A,B)(A & lt;b?乙:甲

typedef結構字典

{

char en【30】;

char zh【30】;

struct Dict * next

} Dict

int main(void)

{

dict * head = 0;

int stuccount = 0;//數量

while(1)

{

Printf(“輸入操作數:1:詞匯輸入2:瀏覽3:漢英4:英漢5:刪除6:退出:“);

int quest

scanf(“% d“,& ampquest);

scanf("%*[^\n】);

if(quest = = 6)break;

else if(quest = = 1)

{

Dict * new Dict =(Dict *)malloc(sizeof(Dict));

Printf(“請輸入中文:“);

scanf(“% 29s“,new dict-& gt;zh);

scanf("%*[^\n】);

Printf(“請輸入英文:“);

scanf(“% 29s“,new dict-& gt;en);

scanf("%*[^\n】);

//插入鏈表的頭部,使最新添加的內容顯示在頂部,很容易看到效果。

new dict-& gt;next = head

head = newDict

++ stuccount;

}

else if(quest = = 2)

{

if(head = = 0)

Printf(“沒話說!\ n ");

其他

{

Printf(“開始瀏覽單詞:\ n“);

while(1)

int st=0,en = min(ST+10,stuccount);

{

printf(“Browse:% d to % d words \ n“,st+1,en);

Dict * stu = head

for(int I = 0;我& ltST;++i)

{

斯圖=斯圖-& gt;接下來;

}

for(int I = ST;我& lten;++i)

{

Printf(“中文:%s英文:%s\n“,stu-& gt;恩,斯圖-& gt;zh);

斯圖=斯圖-& gt;接下來;

}

Printf(“輸入操作號:1向後翻頁;向前2頁;-1 exit:“);

int squest

scanf(“% d“,& ampsquest);

scanf("%*[^\n】);

if(squest = = 1)

{

如果(en!= stu count)ST = en;

}

else if(squest = = 2)

{

ST = max(0,ST-10);

}

else if(squest = =-1)break;

en = min(ST+10,stuccount);

}

}

}

else if(quest = = 3 | | quest = = 4 | | quest = = 5)

{

char a【30】;

if(quest = = 3)printf(“請輸入中文詞匯:“);

else if(quest = = 4)printf(“請輸入英文單詞:“);

else if(quest = = 5)printf(“請輸入要刪除的單詞(中英文均可):”);

scanf(“% 29s“,a);

scanf("%*[^\n】);

Dict * stu = head

dict * lst stu = 0;

int flag = 0;

而(斯圖!= 0 & amp& ampflag==0)

{

if(quest = = 3)

{

if(strcmp(a,stu-& gt;zh)= 0)

{

Printf(“英語:%s\n“,stu-& gt;en);

flag = 1;

}

}

else if(quest = = 4)

{

if(strcmp(a,stu-& gt;en)= 0)

{

Printf(“中文是:%s\n“,stu-& gt;zh);

flag = 1;

}

}

else if(quest = = 5)

{

if(strcmp(a,stu-& gt;en)= = 0 | | strcmp(a,stu-& gt;zh)= 0)

{

stuccount-;

if(lst stu!=0)

lst stu-& gt;next = stu-& gt;接下來;

其他

head = stu-& gt;接下來;

Printf(“已刪除!\ n ");

flag = 1;

}

}

lststu = stu

斯圖=斯圖-& gt;接下來;

}

如果(標誌==0)

{

Printf(“找不到詞匯!\ n ");

}

}

}

返回0;

}

看妳能不能跑。如果有新的需求,我可以繼續寫。代碼應該非常清楚。如果妳什麽都不明白,我可以解釋給妳聽。歡迎提問。