【C++】枚举类型应用

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/CSDN___CSDN/article/details/82946318

运行环境:VS2017

可以参考:【C++】枚举类型

医院内科有A,B,C,D,E,F,G共七位医生,每人在一周内要值一次夜班,排班的要求:

(1)A比C晚一天

(2)D比E晚两天

(3)B比G早三天

(4)F在B和C之间,且在周四

编写程序写出排班顺序

#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
	enum week {mon=1,tue,wed,thu,fri,sat,sun};
	week w;
	int a, b, c, d, e, f, g, loop;
	f = thu;
	cout << "A\t" << "B\t" << "C\t" << "D\t" << "E\t" << "F\t" << "G\t"<<"\n";
	for (a = mon; a <= sun; a++)
		if (a != f)
			for(b=mon;b<=sun;b++)
				if (b < f && b != a)
					for(c=mon;c<=sun;c++)
						if (c != a && c > f&&(c+1==a)&&c!=b)
							for(d=mon;d<=sun;d++)
								if(d!=a&&d!=b&&d!=c&&d!=f)
									for(e=mon;e<=sun;e++)
										if(e!=a&&e!=b&&e!=c&&(e+2==d)&&e!=f)
											for(g=mon;g<=sun;g++)
												if(g!=a&&(g==3+b)&&g!=c&&g!=d&&g!=f&&g!=e)
													for (loop = 1; loop <= 7; loop++)
													{
														switch (loop)
														{
														case 1:w = week(a); break;
														case 2:w = week(b); break;
														case 3:w = week(c); break;
														case 4:w = week(d); break;
														case 5:w = week(e); break;
														case 6:w = week(f); break;
														case 7:w = week(g); break;
														}
														switch (w)
														{
														case mon:cout <<"周一\t"; break;
														case tue:cout <<"周二\t"; break;
														case wed:cout <<"周三\t"; break;
														case thu:cout <<"周四\t"; break;
														case fri:cout <<"周五\t"; break;
														case sat:cout <<"周六\t"; break;
														case sun:cout <<"周日\t"; break;

														}
													}
	cout << endl;
	return 0;
}

阅读更多
换一批

没有更多推荐了,返回首页