值班人员排班系统
问题背景
输入值班人员所选择的休息日期,排出值班人员所有的休息方案
尝试结果
#include
include
include
include
using namespace std;
int n; int rest[7][7]; string choice; char week[7][10]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"}; char weekkk[7][15]={"星期日、","星期一、","星期二、","星期三、","星期四、","星期五、","星期六、"}; char people[7][5]={"赵","钱","孙","李","周","吴","陈"};
bool judge(int x,int y){
for(int i=0;i<7;++i){
cout<
bool judge(int x,int y){ for(int i=0;i<x;++i) if(rest[i][y]==8) return false; return true; }
void show(){ cout<<"Solution: "<<n<<endl; cout<<"赵 钱 孙 李 周 吴 陈"<<endl; cout<<"============================================================="<<endl; for(int i=0;i<7;++i){ for(int j=0;j<7;++j){ if(rest[i][j]==8){ cout<<week[j]<<" "; break; } } } cout<<endl<<endl; }
void dfs(int person){ if(person==7){ n++; show(); return; } for(int j=0;j<7;++j){ if(rest[person][j]==1&&judge(person,j)){ rest[person][j]=8; dfs(person+1); rest[person][j]=1; } } }
int main() { memset(rest,0,sizeof(rest)); cout<<"注意!每次输入完“、”后请输入空格再继续输入!"<<endl; cout<<"注意!每次输入完“、”后请输入空格再继续输入!"<<endl<<endl; distinguish(); cout<<endl; dfs(0); return 0; }
明确问题
这是我在csdn中找的代码看不懂自定义函数的作用
发表回复