资源简介
找了好久,终于找到了一个C语言版的农夫过河问题的解法,认真看就看的懂,写的不错!简介明了!
代码片段和文件信息
#include //0 表示在此岸,1表示在彼岸
struct Condition
{
int farmer;
int wolf;
int goat;
int cabbage;
};
struct Condition conditions [100];
char* action[100];
void takeWolfOver(int i)
{
action[i] = “把狼带到河对岸.“;
conditions[i+1].wolf=1;
conditions[i+1].goat=conditions[i].goat;
conditions[i+1].cabbage=conditions[i].cabbage;
}
void takeWolfBack(int i)
{
action[i] = “把狼带回来.“;
conditions[i+1].wolf=0;
conditions[i+1].goat=conditions[i].goat;
conditions[i+1].cabbage=conditions[i].cabbage;
}
void takegoatOver(int i)
{
action[i] = “把羊带到河对岸.“;
conditions[i+1].wolf=conditions[i].wolf;
conditions[i+1].goat=1;
conditions[i+1].cabbage=conditions[i].cabbage;
}
void takegoatBack(int i)
{
action[i] = “把羊带回来.“;
- 上一篇:C++ RTSP/RTP流媒体服务器源码
- 下一篇:MFC的员工管理系统实现增删改查
评论
共有 条评论