发布网友 发布时间:2023-06-29 14:25
共1个回答
热心网友 时间:2024-12-05 20:05
#include<stdio.h> #include<conio.h> static char *WEEK[7] = {"Sun.", "Mon.", "Tues.", "Wedn.", "Thur.", "Fri.", "Sat."}; int IsChecked(const int pSon[]){ int i, j; for (i=0; i<7; ++i){ for (j=0; j<7&&pSon[j]!=i; ++j); if (j == 7) return 0; } return 1; } void main() { int t=0, j, person[7]; long i; printf("ZHAO, QIAN, SUN, LI, ZHOU, WU, CHEN\n\n"); for (i=0; i<2097152; ++i){ for (j=0; j<7; ++j){ person[j] = (i>>(3*j)) & 7L; } if (!(person[0]==2 || person[0]==4))continue; else if (!(person[1]==1 || person[1]==6))continue; else if (!(person[2]==3 || person[2]==0))continue; else if (!(person[3]==5))continue; else if (!(person[4]==1 || person[4]==4 || person[4]==6))continue; else if (!(person[5]==2 || person[5]==5))continue; else if (!(person[6]==3 || person[6]==6 || person[6]==0))continue; else if (!IsChecked(person)) continue; for (j=0; j<7; ++j){ printf("%s ", WEEK[person[j]]); } printf("\n"); ++t; } printf("\n%d Methods!\n", t); getch(); } 结果: 赵、 钱、 孙、 李、 周、 吴、 陈 四六三五一二日 四一三五六二日 四六日五一二三 四一日五六二三