#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
int main(int argc,char *argv[])
{
std::vector<int>arr[7]
std::vector<std::vector<int>>resolution
for(int i=0i!=7++i)
{
int temp
std::cout<<"please input number "<<i+1
<<" person's all rest days he wanted(1-7):\n"
while(std::cin.peek()!='\n')
{
std::cin>>temp
arr[i].push_back(temp)
}
::getchar()
}
int arr1[]={1,2,3,4,5,6,7}
do
{
for(int i=0i!=7++i)
{
std::vector<int>::iterator iter=
std::find(arr[i].begin(),arr[i].end(),arr1[i])
if(iter==arr[i].end())
{
break
}
if(i==6)
{
std::vector<int>temp(arr1,arr1+7)
resolution.push_back(temp)
}
}
}while(std::next_permutation(arr1,arr1+7))
size_t cnt=resolution.size()
std::cout<<"可用的方案如下,按职员A-G的休息日排洞巧如列:\n"
for(int i=0i!=cnt++i)
{
size_t temp=resolution[i].size()
std::cout<<"方案纳启 "<<i+1<<":\n"
for(int j=0j!=temp++j)
std::cout<<resolution[i][j]<<" "
std::cout<<"\n"
}
::system("pause")
return 0
}
#include <stdio.h>int n = 0
int rest[7][7]
void swap(int *a, int *b)
{
int m
m = *a
*a = *b
*b = m
}
void perm(int list[], int k, int m)
{
int i
int j
if(k >m)
{
for (i=0i<7i++)
{
for (j=0j<7j++)
{
if (rest[i][j] == 0)
return
if (rest[i][j] != list[i])
continue
if (rest[i][j] == list[i])
break
}
}
n++
printf("Solution: %d\n", n)
printf("赵 钱 孙 李 周 吴 陈\n"败咐)
printf("=============================================================\n")
for(i = 0i <= mi++)
{
switch (list[i])
{
case 1: printf("星期一 ")
break
case 2: printf("星期二 ")
break
case 3: printf("星期三 ")
break
case 4: printf("星期四 ")
break
case 5: printf("星期五 ")
break
case 6: printf("星期六 ")
break
case 7: printf("星期日 ")
break
default:
break
}
}
printf("\n\n\n")
}
else
{
for(i = ki <= mi++)
{
swap(&list[k], &list[i])
perm(list, k + 1, m)
swap(&list[k], &list[i])
}
}
}
int main()
{
printf("\n")
printf("注意:\n")
printf("1.请按钱、赵、孙、李、周、吴、陈的顺序输入休息每个人的时间。\n")
printf("2.输入星期时,请直接输入数字,如要输入'星期一',就用'1'代替,以此类推察厅纯。\n")
printf("3.星期与星期之间用空格隔开,每输入完一个人的休息日,在其后输入0,再按回车继续下一人。\n")
printf("\n")
int list[] = {1, 2, 3, 4, 5, 6, 7}
int i, j
for(i = 0i <7i++)
{
printf("伏历请输入第 %d 个人的休息时间:\n", i+1)
for(j = 0j <7j++)
{
scanf("%d", &rest[i][j])
if(rest[i][j] == 0)
break
}
}
printf("\n\n\n")
perm(list, 0, 6)
getchar()
getchar()
printf("输出完毕,按回车键结束!\n")
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)