数据结构,农夫过河。
详细讲述过河#include//0代表在河的这边;1代表在河的对岸structCondition{intfarmer;intwolf;intsheep;intcabbage;};structConditionconditions[100];//结构体条件数组char*action[100];voidtakeWolfOver(inti)//把狼来过去{action[i]="把狼过去.---_-对岸";conditions[i+1].wolf=1;conditions[i+1].sheep=conditions[i].sheep;conditions[i+1].cabbage=conditions[i].cabbage;}voidtakeWolfBack(inti)/*把狼带回来*/{action[i]="带狼回来.本岸对岸";conditions[i+1].wolf=conditions[i].wolf;conditions[i+1].sheep=1;conditions[i+1].cabbage=conditions[i].cabbage;}voidtakeSheepBack(inti)/*把羊带回来*/{action[i]="带羊回来.本岸对岸";conditions[i+1].wolf=conditions[i].wolf;conditions[i+1].sheep=conditions[i].sheep;conditions[i+1].cabbage=1;}voidtakeCabbageBack(inti)/*把菜带回来*/{action[i]="带菜回来.本岸对岸";conditions[i+1].wolf=conditions[i].wolf;conditions[i+1].sheep=conditions[i].sheep;conditions[i+1].cabbage=conditions[i].cabbage;/*全不动*/}voidgetBackBarely(inti)/*返回时的情况*/{action[i]="空手回来.本岸<---(barely)";conditions[i+1].wolf=conditions[i].wolf;conditions[i+1].sheep=conditions[i].sheep;conditions[i+1].cabbage=conditions[i].cabbage;}voidshowSolution(inti)/*显示解决方法*/{intc;printf("\n");printf("%s\n","解决办法:");for(c=0;c<i;c++){printf("step%d:%s\n",c+1,action[c
2024/2/6 8:04:03
4KB
农夫过河
1