#include <string.h>
typedef struct Tpeople
{
int party;
char name[22];
int footFlag;
}Tpeople,PTpeople;
void initPeople(Tpeople people[5]);
int is_li_sun(Tpeople people[5]);
int is_zhao_qian_sun(Tpeople people[5]);
int is_football(Tpeople people[5]);
int is_zhao_zhou_movie(Tpeople people[5]);char *movie = "Movie";
char *football = "Football";
char *restrant = "Restrant";void main()
{
int i , j , k , l , m;
int count = 0;
Tpeople people[5]; // 趙錢孫李周 == 0 1 2 3 4 看電影、踢足球和去餐館 == 0 1 2
int Tbool;
initPeople(people); for(i = 0 ; i != 3; ++i )
{
if(people[0].party == 1)
people[0].footFlag = 1;
else
people[0].footFlag = 0;
for( j = 0; j != 3; ++j)
{
if(people[1].party == 1)
people[1].footFlag = 1;
else
people[1].footFlag = 0;
for( k = 0; k != 3; ++k)
{
if(people[2].party == 1)
people[2].footFlag = 1;
else
people[2].footFlag = 0;
for( l = 0; l != 3; ++l)
{
if(people[3].party == 1)
people[3].footFlag = 1;
else
people[3].footFlag = 0;
for( m = 0; m != 3; ++m)
{
if(people[4].party == 1)
people[4].footFlag = 1;
else
people[4].footFlag = 0;
Tbool = is_li_sun(people)&&is_zhao_qian_sun(people)&&is_football(people)&&is_zhao_zhou_movie(people);
if(Tbool)
{
count = 0;
for(; count != 5; ++count)
{
switch (people[count].party)
{
case 0:
strcpy(people[count].name, "movie");
break;
case 1:
strcpy(people[count].name,"football");
break;
case 2:
strcpy(people[count].name,"restrant");
break;
default:
break;
}
}
printf("Zhao: %s Qian: %s Sun: %s Li: %s Zhou: %s \n",people[0].name,people[1].name,people[2].name,people[3].name,people[4].name);
printf("Zhao: %d Qian: %d Sun: %d Li: %d Zhou: %d \n",people[0].party,people[1].party,people[2].party,people[3].party,people[4].party);
printf("\n");
}
people[4].party++;
}
people[4].party = 0;
people[3].party++; }
people[3].party = 0;
people[2].party++; }
people[2].party = 0;
people[1].party++; }
people[1].party = 0;
people[0].party++; }
}void initPeople(Tpeople people[5])
{
int i = 0;
for (;i !=5 ; ++i)
{
people[i].party = 0;
people[i].footFlag = 0;
}
}int is_li_sun(Tpeople people[5])
{
if(people[2].party == people[3].party)
return 0;
return 1;
}int is_zhao_qian_sun(Tpeople people[5])
{
if( (people[0].party != people[1].party) && (people[1].party != people[2].party) && (people[0].party != people[2].party))
return 1;
return 0;
}int is_football(Tpeople people[5])
{
int i,count = 0;
for(i = 0; i != 5; ++i)
if(people[i].footFlag == 1)
count++;
if(count == 2)
return 1;
return 0;
}int is_zhao_zhou_movie(Tpeople people[5])
{
if(((people[0].party == 0) && (people[4].party == 0)) || ((people[0].party != 0) && (people[4].party != 0)))
return 1;
return 0;
}