#include<bits/stdc++.h>
#define ll long long
#define ios ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);
using namespace std;
int months[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
unordered_map<string,int>res;
struct Time
{
int year,month,day,hour,minutes,week;
Time(string s)
{
sscanf(s.c_str(),"%4d%2d%2d%2d%2d",&year,&month,&day,&hour,&minutes);
}
bool operator < (const Time&x)const
{
if(x.year!=year) return year<x.year;
if(month!=x.month) return month<x.month;
if(day!=x.day) return day<x.day;
if(hour!=x.hour) return hour<x.hour;
return minutes<x.minutes;
}
int judge()
{
if(year%4==0&&year%100||year%400==0)
return 1;
return 0;
}
int get_day()
{
if(month==2) return months[2]+judge();
return months[month];
}
void next()
{
if(++minutes==60)
{
minutes=0;
if(++hour==24)
{
hour=0;
week=(week+1)%7;
if(++day>get_day())
{
day=1;
if(++month>12)
{
month=1;
++year;
}
}
}
}
}
string print()
{
char c[200];
sprintf(c,"%4d%02d%02d%02d%02d",year,month,day,hour,minutes);
return c;
}
};
struct task
{
bool month[13],day_of_month[32],day_of_week[7],hour[24],minutes[60];
string com;
bool check(Time t)
{
return month[t.month]&&hour[t.hour]&&minutes[t.minutes]&&day_of_month[t.day]
&&day_of_week[t.week];
}
}Task[25];
void init()
{
string s[]={ "jan", "feb", "mar", "apr", "may", "jun",
"jul", "aug", "sep", "oct", "nov", "dec",
"sun", "mon", "tue", "wed", "thu", "fri",
"sat"};
int values[]={1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12,
0, 1, 2, 3, 4, 5,
6};
for(int i=0;i<19;i++)
res[s[i]]=values[i];
}
int get(string y)
{
if(y[0]>='0'&&y[0]<='9') return stoi(y);
string s;
for(auto c:y)
s+=tolower(c);
return res[s];
}
void work(string str,bool st[],int len)
{
for(int i=0;i<str.length();i++)
{
int j=i;
while(j<str.length()&&str[j]!=',') j++;
string s=str.substr(i,j-i);
i=j;
int index=s.find('-');
if(s=="*")
for(int i=0;i<len;i++)
st[i]=true;
else if(index==-1)
st[get(s)]=true;
else
{
int l=get(s.substr(0,index)),r=get(s.substr(index+1));
for(int i=l;i<=r;i++)
st[i]=true;
}
}
}
int main()
{
int n;
init();
string start,send;
cin>>n>>start>>send;
for(int i=0;i<n;i++)
{
string tmonth,thour,tminutes,tday_of_week,tday_of_month,tcom;
cin>>tminutes>>thour>>tday_of_month>>tmonth>>tday_of_week>>tcom;
work(tminutes,Task[i].minutes,60);
work(thour,Task[i].hour,24);
work(tday_of_month,Task[i].day_of_month,32);
work(tmonth,Task[i].month,13);
work(tday_of_week,Task[i].day_of_week,7);
Task[i].com=tcom;
}
Time t("197001010000"),s(start),e(send),r("201711170700");
t.week=4;
while(t<e)
{
if(!(t<s))
{
for(int i=0;i<n;i++)
if(Task[i].check(t))
{
cout<<t.print()<<" "<<Task[i].com<<endl;
}
}
t.next();
}
return 0;
}
|