#include <bits/stdc++.h>
using namespace std;
char vMon[][4]={"","jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"};
char vWek[][4]={"sun","mon","tue","wed","thu","fri","sat"};
int mtharray[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
map<string,int> mMon,mWek;
map<string,vector<string> > mrt;
void buildMonAndWekMap()
{
for(int i=1;i<=12;++i) mMon[vMon[i]]=i;//月份
for(int i=0;i<=6;++i) mWek[vWek[i]]=i;//星期
}
string to_string_x(int n)//c++11 surport
{
stringstream ss;
ss<<n;
return ss.str();
}
int stoi_x(const string &str)//c++11 surport
{
int ans;
stringstream ss(str);
ss>>ans;
return ans;
}
void toStandard(string &str)//转化为标准小写
{
int len=str.size();
for(int i=0;i<len;++i)str[i]=tolower(str[i]);
}
vector<string> splitStringAndbuildVector(string &str,int TAG)//TAG=0(other),1(month),2(dayofweek);
{
str+=",";
vector<string> vret;
size_t found=str.find(",");
while(found!=string::npos)
{
string x=str.substr(0,found);
str=str.substr(found+1,str.size()-found-1);
size_t fdx=x.find("-");
if(fdx==string::npos)//非连续值
{
if(TAG==1&&isalpha(x[0])) x=to_string_x(mMon[x]);//是month英文缩写,转换为数字
if(TAG==2&&isalpha(x[0])) x=to_string_x(mWek[x]);//是day of week英文缩写,转换为数字
if(x.size()==1) x="0"+x;//添加0
vret.push_back(x);
}
else//连续值
{
string L=x.substr(0,fdx),R=x.substr(fdx+1,x.size()-fdx-1);
int left,right;
if(TAG==0) left=stoi_x(L),right=stoi_x(R);
else if(TAG==1)//month
{
left=(isalpha(L[0]))?mMon[L]:stoi_x(L);
right=(isalpha(R[0]))?mMon[R]:stoi_x(R);
}
else if(TAG==2)//day of week
{
left=(isalpha(L[0]))?mWek[L]:stoi_x(L);
right=(isalpha(R[0]))?mWek[R]:stoi_x(R);
}
while(left<=right)
{
string num=to_string_x(left);
if(num.size()==1)num="0"+num;
vret.push_back(num);
++left;
}
}
found=str.find(",");
}
return vret;
}
bool isleapyear(int y)
{
return (y%4==0&&y%100)||y%400==0;
}
string getWeekday(string year,string month,string day)
{
int y=stoi_x(year),m=stoi_x(month),d=stoi_x(day);
int by=1970,countday=0;
while(by<y)
{
countday+=(isleapyear(by))?366:365;
++by;
}
for(int i=1;i<m;++i) countday+=mtharray[i];
countday+=d-1;
return "0"+to_string_x((4+countday%7)%7);
}
int main()
{
int n;
string st,et;
buildMonAndWekMap();
cin>>n>>st>>et;
string syy=st.substr(0,4),smm=st.substr(4,2),sdd=st.substr(6,2),sHH=st.substr(8,2),sMM=st.substr(10,2);
string eyy=et.substr(0,4),emm=et.substr(4,2),edd=et.substr(6,2),eHH=et.substr(8,2),eMM=et.substr(10,2);
int syInt=stoi_x(syy),eyInt=stoi_x(eyy);
while(n--)
{
vector<string> vmts,vhur,vdfm,vmth,vdfw;
string minutes,hours,dofmon,month,dofwek,command;
cin>>minutes>>hours>>dofmon>>month>>dofwek>>command;
toStandard(month);//不区别大小写,转化为标准小写
toStandard(dofwek);//不区别大小写,转化为标准小写
if(minutes=="*") minutes="0-59";
vmts=splitStringAndbuildVector(minutes,0);//应该执行的分钟
if(hours=="*") hours="0-23";
vhur=splitStringAndbuildVector(hours,0); //应该执行的小时
if(dofmon=="*") dofmon="1-31";
vdfm=splitStringAndbuildVector(dofmon,0);//应该执行的日期
if(month=="*") month="1-12";
vmth=splitStringAndbuildVector(month,1);//应该执行的月份
if(dofwek=="*") dofwek="0-6";
vdfw=splitStringAndbuildVector(dofwek,2);//应该周几执行
set<string> wekexist;
for(size_t i=0;i<vdfw.size();++i) wekexist.insert(vdfw[i]);//更快的检索当前日期(dayofweek)是不是应该执行
int curyear=syInt;//从开始年份执行
while(curyear<=eyInt)
{
if(isleapyear(curyear)) mtharray[2]=29;//leapyear的2月份应该是29天
else mtharray[2]=28;
string year=to_string_x(curyear);//年份
for(size_t mi=0;mi<vmth.size();mi++)//month
{
string curm=vmth[mi];//当前月份
for(size_t di=0;di<vdfm.size();di++)//day of month
{
string curd=vdfm[di];//当前日期
string wd=getWeekday(year,curm,curd);//该年,该月,该日是星期几
if(wekexist.count(wd)==0||stoi_x(curd)>mtharray[stoi_x(curm)])continue;
//命令行中不包含该星期或者当前天数超过当前月份的应有天数时
for(size_t Hi=0;Hi<vhur.size();++Hi)//hour
{
for(size_t Mi=0;Mi<vmts.size();++Mi)//minutes
{
string datetime=year+curm+curd+vhur[Hi]+vmts[Mi];
if(datetime>=st&&datetime<et) mrt[datetime].push_back(command);//在当前日期时间内
}
}
}
}
++curyear;//进入下一年
}
}
for(map<string,vector<string> >::iterator it=mrt.begin();it!=mrt.end();++it)
{
map<string,int> isprt;
for(size_t i=0;i<it->second.size();++i)
{
string dis=it->first+" "+it->second[i];
if(isprt.count(dis)==0)
{
cout<<dis<<endl;
isprt[dis]=1;
}
}
}
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
ccf计算机职业资格认证的题解
共61个文件
cpp:61个
需积分: 5 0 下载量 4 浏览量
2024-03-31
14:48:32
上传
评论
收藏 64KB ZIP 举报
温馨提示
ccfcsp历年考试真题解答 ccf计算机职业资格认证的题解
资源推荐
资源详情
资源评论
收起资源包目录
ccf-csp-code.zip (61个子文件)
ccf-csp-code
201703-2 学生排队 ccf .cpp 611B
201712-2 游戏 ccf.cpp 363B
201312-4 有趣的数 ccf.cpp 2KB
201612-2 工资计算 ccf .cpp 525B
201409-2 画图 ccf .cpp 457B
201812-1 小明上学 ccf.cpp 381B
201803-2 碰撞的小球 ccf.cpp 814B
201609-2 火车购票 ccf.cpp 691B
201609-4 交通规划 ccf.cpp 1KB
201803-1 跳一跳 ccf.cpp 398B
201612-3 权限查询 ccf .cpp 2KB
201509-3 模板生成系统 ccf .cpp 771B
201509-2 日期计算 ccf .cpp 395B
201709-2 公共钥匙盒 ccf .cpp 1KB
201604-4 游戏 ccf.cpp 1KB
201609-1 最大波动 ccf.cpp 277B
201412-2 Z字形扫描 ccf .cpp 702B
201604-1 折点计数 ccf.cpp 338B
201503-1 图像旋转 ccf .cpp 347B
201512-4 送货 ccf .cpp 1KB
201809-1 卖菜 ccf.cpp 427B
201503-2 数字排序 ccf .cpp 581B
201712-3 Crontab ccf.cpp 6KB
201709-5 除法 ccf .cpp 906B
201703-4 地铁修建 ccf .cpp 819B
201709-3 JSON查询 ccf .cpp 2KB
201709-1 打酱油 ccf .cpp 235B
201312-3 最大的矩形 ccf .cpp 375B
201809-3 元素选择器 ccf.cpp 2KB
201604-2 俄罗斯方块 ccf .cpp 994B
201403-3 命令行选项 ccf .cpp 1KB
201512-3 画图 ccf .cpp 2KB
201709-4 通信网络 ccf .cpp 745B
201609-3 炉石传说 ccf .cpp 2KB
201612-1 中间数 ccf.cpp 372B
201809-4 再卖菜 ccf.cpp 1006B
201403-1 相反数 ccf .cpp 291B
201803-3 URL映射 ccf.cpp 2KB
201509-1 数列分段 ccf .cpp 310B
201712-1 最小差值 ccf.cpp 317B
201409-4 最优配餐 ccf.cpp 986B
201409-3 字符串匹配 ccf .cpp 696B
201703-3 Markdown ccf .cpp 2KB
201403-2 窗口 ccf .cpp 940B
201412-1 门禁系统 ccf .cpp 281B
201503-4 网络延时 ccf.cpp 808B
201409-1 相邻数对 ccf .cpp 388B
201312-1 出现次数最多的数 ccf.cpp 402B
201312-2 ISBN号码 ccf .cpp 503B
201809-2 买菜 ccf.cpp 338B
201503-3 节日 ccf .cpp 945B
201412-4 最优灌溉 ccf .cpp 764B
201803-4 棋局评估 ccf.cpp 2KB
201512-1 数位之和 ccf.cpp 147B
201403-4 无线网络 ccf.cpp 1KB
201703-1 分蛋糕 ccf .cpp 317B
201612-4 压缩编码 ccf .cpp 588B
201712-4 行车路线 ccf.cpp 2KB
201412-3 集合竞价 ccf .cpp 1KB
201512-2 消除类游戏 ccf .cpp 980B
201509-4 高速公路 ccf .cpp 952B
共 61 条
- 1
资源评论
MarcoPage
- 粉丝: 2305
- 资源: 1101
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功