#include
#include
typedef struct cy
{
char idiom[9];
char star[3];
char end[3];
}CY;
int main()
{
int i,meNum,cont=0,flag = 1,f=0,z;
CY cy1,cy2;
char an,menu[10][11]={"胸有成竹","一心一意","花好月圆","风和日丽","豆蔻年华","学富五车","相辅相成","先发制人","兴高采烈","自由输入"};
char library[20][11]={"车水马龙","腾云驾雾","花好月圆","竹篮打水","水深火热","天经地义","人声鼎沸","辞新迎旧","烈火真金","立竿见影","成事在人","沸沸扬扬","丽句清词","意味深长","入不敷出","地大物博","华而不实","说来话长","死不瞑目"};
for(i=0;i<11;i++)library[19][i]=1;
printf("成语接龙游戏\n");
while(1)
{
printf("请选择开头的成语,输入序号1-9,自行输入请选择0:\n");
for(i=0;i<9;i++)
printf("%d、--%s\n",i+1,menu[i]);
printf("%d、--%s\n",0,menu[i]);
scanf("%d",&meNum);
memset(cy1.idiom,0,9);
memset(cy1.end,0,3);
if(meNum==0)
{
printf(" 请输入开头的成语:");
scanf("%s",cy1.idiom);
}
else
strcpy(cy1.idiom,menu[meNum-1]);
cy1.end[0]=cy1.idiom[6];
cy1.end[1]=cy1.idiom[7];
cy1.end[2]=0;
printf("成语接龙开始,输入0结束\n");
printf(">>>>>>>>>>>>>>>>>>>>>>\n");
printf(" %s\n",cy1.idiom);
while(1)
{
printf(" -->");
memset(cy2.idiom,0,9);
memset(cy2.star,0,3);
if(flag == 1)
{
for(i=0;i<20;i++)
{
strcpy(cy2.idiom,library[i]);
if(cy2.idiom[0]==1 && cy2.idiom[1]==1)
{
printf("你赢了!\n");
f=1;
break;
}
cy2.star[0]=cy2.idiom[0];
cy2.star[1]=cy2.idiom[1];
cy2.star[2]=0;
if(strcmp(cy1.end,cy2.star))
{
continue;
}
printf("%s\n",cy2.idiom);
memset(cy1.idiom,0,9);
strcpy(cy1.idiom,cy2.idiom);
cy1.end[0]=cy1.idiom[6];
cy1.end[1]=cy1.idiom[7];
cy1.end[2]=0;
break;
}
flag = 2;
if(f==1)break;
continue;
}
if(flag == 2)
{
z=0;
scanf("%s",cy2.idiom);
for(i=0;i<20;i++)
{
if(strcmp(cy2.idiom,library[i]))
{
continue;
}
else
{
z=1;
break;
}
}
if(cy2.idiom[0]=='0' && cy2.idiom[1]==0)
break;
cy2.star[0]=cy2.idiom[0];
cy2.star[1]=cy2.idiom[1];
cy2.star[2]=0;
if(strcmp(cy1.end,cy2.star)||z==0)
{
printf("接龙失败!\n");
break;
}
cont++;
memset(cy1.idiom,0,9);
strcpy(cy1.idiom,cy2.idiom);
cy1.end[0]=cy1.idiom[6];
cy1.end[1]=cy1.idiom[7];
cy1.end[2]=0;
flag = 1;
continue;
}
}
printf("本次接龙结束!你共完成了%d个成语的接龙\n",cont);
getchar();
while(1)
{
printf("再玩儿一次(Y/N)?");
scanf("%c",&an);
if(an=='N')
return 0;
if(an=='Y')
break;
}
}
return 0;
}
本程序基于百度上的成语接龙程序进行改编,原链接位置为emmmmmmmm (滑稽),实在是想不起来了,源程序只是玩家自己进行成语接龙游戏,本人添加了“人机对战”,即系统输出一次,然后玩家输入一次,知道系统未找到合适成语或者玩家未答出成语为止。
目前,成语库只能通过在Library二维数组添加额外成语来进行扩充,如果需要扩充成语库,需要修改如下位置