#include<stdio.h>
#include<algorithm>
using namespace std;
short surname[5]={0,1,2,3,4};//从0~4分别为谷,王,李,刘,高
short name[5]={0,1,2,3,4};//从0~4分别为爱欣,晓宁,瑞英,芸菲,莹莹
short crs[5]={0,1,2,3,4};//从0~4分别为美术,音乐,数学,语文,英语
short grade[5]={0,1,2,3,4};//从0~4分别为一到五年级
bool JudgeCourse() //符合返回真
{
for(short i=0;i<5;i++)
{
if((name[i]==0)!=(crs[i]==0)) return false; //爱欣是美术老师
if((surname[i]==1)!=(crs[i]==1)) return false;//王老师是音乐老师
if(name[i]==1&&crs[i]==2) return false; //晓宁不是数学老师
if((name[i]==3)!=(crs[i]==3)) return false; //芸菲是语文老师
if((surname[i]==3)!=(crs[i]==4)) return false;//刘老师是英语老师
}
return true;
}
bool JudgeGrade() //符合返回真
{
for(short i=0;i<5;i++)
{
if(surname[i]==0&&grade[i]==1) return false; //谷老师不是二年级老师
if(surname[i]==2&&grade[i]==3) return false; //李老师不是四年级老师
if((name[i]==2)!=(grade[i]==0)) return false; //瑞英教一年级学生
if(name[i]==3&&grade[i]==2) return false; //芸菲不教三年级
if((surname[i]==4)!=(grade[i]==4)) return false;//高老师教五年级
if((name[i]==4)!=(grade[i]==3)) return false;//莹莹教四年级
}
return true;
}
int main()
{
bool success=false;
do
{
for(short icrs=0;icrs<5;icrs++) crs[icrs]=icrs;
do
{
if(!JudgeCourse()) continue;
for(short igrade=0;igrade<5;igrade++) crs[igrade]=igrade;
do
{
if(JudgeGrade())success=true;
}while(!success&&next_permutation(grade,grade+5));
}while(!success&&next_permutation(crs,crs+5));
}while(!success&&next_permutation(name,name+5));
for(short i=0;i<5;i++)
{
switch(surname[i])
{
case 0:printf("%s","谷");break;
case 1:printf("%s","王");break;
case 2:printf("%s","李");break;
case 3:printf("%s","刘");break;
default:printf("%s","高");break;
}
switch(name[i])
{
case 0:printf("%s","爱欣老师教");break;
case 1:printf("%s","晓宁老师教");break;
case 2:printf("%s","瑞英老师教");break;
case 3:printf("%s","芸菲老师教");break;
default:printf("%s","莹莹老师教");break;
}
switch(grade[i])
{
case 0:printf("%s","一年级");break;
case 1:printf("%s","二年级");break;
case 2:printf("%s","三年级");break;
case 3:printf("%s","四年级");break;
default:printf("%s","五年级");break;
}
switch(crs[i])
{
case 0:printf("%s","美术\n");break;
case 1:printf("%s","音乐\n");break;
case 2:printf("%s","数学\n");break;
case 3:printf("%s","语文\n");break;
default:printf("%s","英语\n");break;
}
}
return 0;
}