CCF201712-3 Crontab(100分)

试题编号: 201712-3
试题名称: Crontab
时间限制: 10.0s
内存限制: 256.0MB
问题描述:

CCF201712-3 Crontab(100分)_第1张图片
CCF201712-3 Crontab(100分)_第2张图片CCF201712-3 Crontab(100分)_第3张图片
CCF201712-3 Crontab(100分)_第4张图片

样例输入

3 201711170032 201711222352
0 7 * * 1,3-5 get_up
30 23 * * Sat,Sun go_to_bed
15 12,18 * * * have_dinner

样例输出

201711170700 get_up
201711171215 have_dinner
201711171815 have_dinner
201711181215 have_dinner
201711181815 have_dinner
201711182330 go_to_bed
201711191215 have_dinner
201711191815 have_dinner
201711192330 go_to_bed
201711200700 get_up
201711201215 have_dinner
201711201815 have_dinner
201711211215 have_dinner
201711211815 have_dinner
201711220700 get_up
201711221215 have_dinner
201711221815 have_dinner

问题连接:CCF201712-3 Crontab

解题思路:直接模拟,具体看程序注释。

提交后得100分的C++程序:

#include
#include
#include
#include
#include
#include
 
using namespace std;
 
int days[]={0,31,28,31,30,31,30,31,31,30,31,30,31};

//月份表和星期表 
string m[13]={"","jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"};
string w[7]={"sun","mon","tue","wed","thu","fri","sat"}; 

//字符串转整数 
int myatoi(string s)
{
	int res=0;
	for(int i=0;i2&&isleap(y))
	  sum++;
	sum--;//保证输入1970 1 1输出0 
	return sum;
}

//月份、星期映射 
int mymap(int op,string s)
{
	if(op==3)//返回月份的映射
	{
		for(int i=1;i<13;i++)
	      if(m[i]==s)
	        return i; 
	}
	else if(op==4)//返回星期的映射
	{
		for(int i=0;i<7;i++)
	      if(w[i]==s)
	        return i;
	}
	return -1;
}
 
struct Time{
	int y,m,d,h,min;
	Time(string s){//yyyymmddHHMM格式 
		string str;
		str=s.substr(0,4),y=myatoi(str);
		str=s.substr(4,2),m=myatoi(str);
		str=s.substr(6,2),d=myatoi(str);
		str=s.substr(8,2),h=myatoi(str);
		str=s.substr(10,2),min=myatoi(str);
	}
};
 
void read(vector > &p,char *a,int op)
{
	vectortmp;
	string s1,s2;
	//用 ","进行分割,结果保存在tmp中
	char *sp=strtok(a,",");
	while(sp){
		tmp.push_back(sp);
		sp=strtok(NULL,",");
	} 
	//用 "-"进行分割
	for(int i=0;i > &v)
{
	for(int i=0;ie.m) return false;
	if(me.d) return false;
	if(de.h) return false;
	if(he.min) return false;
	if(mina.id):(time>a.time);
	}
};

vector >v[5];//0-5分别表示 min,h,d,m,w的范围,如果是 * 则用<-1,-1>表示 



int main()
{
	int n;
	string s,t;
	//读入数据 
	cin>>n>>s>>t;
	Time st(s),et(t);
	priority_queueq;//结果队列 
	for(int i=0;i>s;//任务名
		int m=st.m,d=st.d,h=st.h,min=st.min; 
		for(int y=st.y;y<=et.y;y++,m=1)
		  for(;m<=12;m++,d=1)
		    if(judge(m,v[3]))//满足月份
		    {
		  	  int up=days[m];
		  	  if(m==2&&isleap(y))
		  	    up++;
		  	  for(;d<=up;d++,h=0)
		  	    if(judge(d,v[2])&&judge((sum(y,m,d)+4)%7,v[4]))//满足号数和星期数 
				{
					for(;h<24;h++,min=0)
					  if(judge(h,v[1]))//满足小时数 
					  {
					  	 for(;min<60;min++)
					  	 {
						     if(!end_time(y,m,d,h,min,et))//结束 
						       break;
					         if(judge(min,v[0]))//满足分钟数
						     {
							  	long long time=(long long)y*100000000+(long long)m*1000000+(long long)d*10000+(long long)h*100+min;
							  	q.push(Result(i,time,s));
						     } 
					     }
				    }
		       }
			}		
		}
	while(!q.empty())
	{
		Result f=q.top();
		cout<

 

你可能感兴趣的:(ACM__模拟,CCF,CSP,认证考试)