没想像中的容易啊,有些问题写的时候才发现....搞了半天总算搞好了....
程序代码:
#include "stdio.h"
#include "stdlib.h"
int c[7] = {0}; //分别代表A,B,C教的两门课, c[0]空着不用
int c_t[20][7] = {0}; //存放结果....
int c_t_i = 0; //不说了,说多了都是泪啊
int check_c6 (void);
int check_c2 (int c1, int c2);
void store (void);
void print_result (void);
int whether_store (void);
int main (void)
{
for (c[1]=1; c[1]<=6; c[1]++)
{
for (c[2]=1; c[2]<=6; c[2]++)
{
for (c[3]=1; c[3]<=6; c[3]++)
{
for (c[4]=1; c[4]<=6; c[4]++)
{
for (c[5]=1; c[5]<=6; c[5]++)
{
for (c[6]=1; c[6]<=6; c[6]++)
{
if (check_c6 ())
{
continue;
}
if (check_c2 (1, 3))
{
continue;
}
if (check_c2 (1, 4))
{
continue;
}
if (check_c2 (3, 4))
{
continue;
}
if (check_c2 (1, 5))
{
continue;
}
if (c[1]==3||c[1]==4||c[2]==3||c[2]==4)
{
continue;
}
if (c[3]==4||c[4]==4)
{
continue;
}
if (c[3]==1||c[3]==5||c[4]==1||c[4]==5)
{
continue;
}
if (whether_store ())
{
continue;
}
store ();
}
}
}
}
}
}
print_result ();
system ("pause");
return 0;
}
int check_c6 (void)
{
for (int i=2,j=1; j<=6; i++)
{
if (j == i)
{
i++;
if (j == 6)
{
break;
}
}
if (c[j] == c[i])
{
return 1;
}
if (i == 6)
{
j++;
i = 0;
}
}
return 0;
}
int check_c2 (int c1, int c2)
{
if ((c[1]==c1&&c[2]==c2)||(c[1]==c2&&c[2]==c1))
{
return 1;
}
if ((c[3]==c1&&c[4]==c2)||(c[3]==c2&&c[4]==c1))
{
return 1;
}
if ((c[5]==c1&&c[6]==c2)||(c[5]==c2&&c[6]==c1))
{
return 1;
}
return 0;
}
void store (void)
{
for (int i=1; i<=6; i++)
{
c_t[c_t_i][i] = c[i];
}
c_t_i++;
}
void print_result (void)
{
for (int i=0; i<=c_t_i-1; i++)
{
printf ("********** \n%d \t%d \n%d \t%d \n%d \t%d \n", c_t[i][1], c_t[i][2], c_t[i][3], c_t[i][4], c_t[i][5], c_t[i][6]);
}
}
int whether_store (void)
{
for (int i=0; i<=c_t_i-1; i++)
{
if ((c[1]==c_t[i][2]&&c[2]==c_t[i][1])||(c[3]==c_t[i][4]&&c[4]==c_t[i][3])||(c[5]==c_t[i][6]&&c[6]==c_t[i][5]))
{
return 1;
}
}
return 0;
}
大家将就着看吧...
[
本帖最后由 pycansi 于 2013-11-5 18:50 编辑 ]