来关心关心女老师。
五位女教师:谷老师不是二年级老师
爱欣是美术老师
王老师是音乐老师
晓宁不是数学老师
李老师不是四年级老师
瑞英教一年级学生
芸菲是语文老师
刘老师是英语老师
芸菲不教三年级
高老师教五年级
莹莹教四年级
问:每一位老师全名及教哪一年级哪一门课
挺有意思的,供大家练练手。
#include <iostream> #include <string> #include <algorithm> using namespace std; int main( void ) { string family_names[] = { "李", "谷", "高", "王", "刘" }; string given_names[] = { "瑞英", "芸菲", "莹莹", "爱欣", "晓宁" }; string grade_names[] = { "一年级", "二年级", "三年级", "四年级", "五年级" }; string subject_names[] = { "语文", "数学", "英语", "美术", "音乐" }; auto grade_with_familyname = [&]( const char* family_name ) { return grade_names[distance(begin(family_names),find(begin(family_names),end(family_names),family_name))]; }; auto grade_with_givenname = [&]( const char* given_name ) { return grade_names[distance(begin(given_names),find(begin(given_names),end(given_names),given_name))]; }; auto subject_with_familyname = [&]( const char* family_name ) { return subject_names[distance(begin(family_names),find(begin(family_names),end(family_names),family_name))]; }; auto subject_with_givenname = [&]( const char* given_name ) { return subject_names[distance(begin(given_names),find(begin(given_names),end(given_names),given_name))]; }; sort( begin(given_names), end(given_names) ); do { sort( begin(grade_names), end(grade_names) ); do { sort( begin(subject_names), end(subject_names) ); do { if( grade_with_familyname("谷") != "二年级" && subject_with_givenname("爱欣") == "美术" && subject_with_familyname("王") == "音乐" && subject_with_givenname("晓宁") != "数学" && grade_with_familyname("李") != "四年级" && grade_with_givenname("瑞英") == "一年级" && subject_with_givenname("芸菲") == "语文" && subject_with_familyname("刘") == "英语" && grade_with_givenname("芸菲") != "三年级" && grade_with_familyname("高") == "五年级" && grade_with_givenname("莹莹") == "四年级" ) { cout << family_names[0] << given_names[0] << grade_names[0] << subject_names[0] << '\n' << family_names[1] << given_names[1] << grade_names[1] << subject_names[1] << '\n' << family_names[2] << given_names[2] << grade_names[2] << subject_names[2] << '\n' << family_names[3] << given_names[3] << grade_names[3] << subject_names[3] << '\n' << family_names[4] << given_names[4] << grade_names[4] << subject_names[4] << '\n' << endl; } } while( next_permutation(begin(subject_names),end(subject_names)) ); } while( next_permutation(begin(grade_names),end(grade_names)) ); } while( next_permutation(begin(given_names),end(given_names)) ); }