成语验证,需要将成语字典做成库,然后查询匹配,你想做自己做个库吧。
#include<stdio.h>#include<string.h>
typedef struct cy
{
char idiom[9]
char star[3]
char end[3]
}CY
int main()
{
int i,meNum,cont=0
CY cy1,cy2
char an,menu[10][11]={"胸有成竹","一心一意","花好月圆","风和日丽","豆蔻年华","学富五车","相辅相成","先发制人","兴高采烈","自由输入"}
printf("成语接龙游戏\n")
while(1)
{
printf("请选择开头的成语,输入序号1-9,自行输入请选择0:\n")
for(i=0i<9i++)
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)
scanf("%s",cy2.idiom)
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))
{
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
}
printf("本次接龙结束!你共完成了%d个成语的接龙\n",cont)
getchar()
while(1)
{
printf("再玩儿一次(Y/N)?")
scanf("%c",&an)
if(an=='N')
return 0
if(an=='Y')
break
}
}
return 0
}
int main(){
char first[20] = {0}
char second[20] = {0}
char key[20] = {0}
//input
printf("please input first word:")
scanf("%s", first)
printf("please input second word:")
scanf("%s", second)
//begin
bool found = false
for (int i = 0 i < 20 i ++)
{
char tmp = first[i]
if (tmp == second[0])
{
found = true
}
if (found == true)
{
int len = 0
for (int l = i, j = 0 l < 20, j < 20 l ++, 桐唯j ++)
{
if (first[l] != 0)
{
迅亮 key[j] = first[l]
len ++
}
else
break
局昌培 }
for (int j = 0 j < len j ++)
{
if (key[j] != second[j])
{
found = false
memset(key, 0x00, sizeof(key)/sizeof(key[0]))
}
}
if (found)
printf("the max keyword is: %s \n", key)
else
printf("can not found the key word!! \n")
}
}
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)