#include <stdio.h>

class State;

// 工作
class Work
{
public:
	Work();
	~Work();
	
	void SetState(State* s);
	void WriteProgram();
	
	int Hour;
	bool Finished;
protected:
	State* current;
};

// 抽象状态
class State
{
public:
	virtual void WriteProgram(Work* w)=0;
};

// 下班休息状态
class RestState : public State
{
public:
	virtual void WriteProgram(Work* w)
	{
		printf("当前时间：%d点 下班回家了\n",w->Hour);
	}
};

// 睡眠状态
class SleepingState : public State
{
public:
	virtual void WriteProgram(Work* w)
	{
		printf("当前时间：%d点 不行了，睡着了。\n",w->Hour);
	}
};

// 晚间工作状态
class EveningState : public State
{
public:
	virtual void WriteProgram(Work* w)
	{
		if(w->Finished)
		{
			w->SetState(new RestState());
			w->WriteProgram();
		}
		else
		{
			if(w->Hour < 21) printf("当前时间：%d点 加班哦，疲累之极\n",w->Hour);
			else
			{
				w->SetState(new SleepingState());
				w->WriteProgram();
			}
		}
	}
};

// 下午工作状态
class AfternoonState : public State
{
public:
	virtual void WriteProgram(Work* w)
	{
		if(w->Hour < 17) printf("当前时间：%d点 下午状态还不错，继续努力\n",w->Hour);
		else
		{
			w->SetState(new EveningState());
			w->WriteProgram();
		}
	}
};

// 中午工作状态
class NoonState : public State
{
public:
	virtual void WriteProgram(Work* w)
	{
		if(w->Hour < 13) printf("当前时间：%d点 饿了，午饭；犯困，午休。\n",w->Hour);
		else
		{
			w->SetState(new AfternoonState());
			w->WriteProgram();
		}
	}
};

// 上午工作状态
class ForenoonState : public State
{
public:
	virtual void WriteProgram(Work* w)
	{
		if(w->Hour < 12) printf("当前时间：%d点 上午工作，精神百倍\n",w->Hour);
		else
		{
			w->SetState(new NoonState());
			w->WriteProgram();
		}
	}
};

Work::Work()
{
	current = new ForenoonState();
}

Work::~Work()
{
	delete current;
}

void Work::SetState(State* s)
{
	delete current;
	current = s;
}

void Work::WriteProgram()
{
	current->WriteProgram(this);
}

int main()
{
	Work* emergencyProjects = new Work();
	emergencyProjects->Hour = 9;
	emergencyProjects->WriteProgram();
	emergencyProjects->Hour = 10;
	emergencyProjects->WriteProgram();
	emergencyProjects->Hour = 12;
	emergencyProjects->WriteProgram();
	emergencyProjects->Hour = 13;
	emergencyProjects->WriteProgram();
	emergencyProjects->Hour = 14;
	emergencyProjects->WriteProgram();
	emergencyProjects->Hour = 17;
	emergencyProjects->Finished = false;
	emergencyProjects->WriteProgram();
	emergencyProjects->Hour = 19;
	emergencyProjects->WriteProgram();
	emergencyProjects->Hour = 22;
	emergencyProjects->WriteProgram();

	delete emergencyProjects;
	
	return 0;
}