营销型网站制作msgg,wordpress page 分页,做网站公司赚钱吗,企业管理咨询经营范围有哪些目录
1.如何判断闰年
2.如何遍历当前年份的每一天
3.如果想要输出某一年某一天到某一年某一天之间一共有多少天。
4.精确到具体周几到周几的问题分析
5.如何直接通过一层for循环枚举年月日
习题#xff1a; 蓝桥杯竞赛特别喜欢考日期问题#xff0c;今天给大家分享一下…目录
1.如何判断闰年
2.如何遍历当前年份的每一天
3.如果想要输出某一年某一天到某一年某一天之间一共有多少天。
4.精确到具体周几到周几的问题分析
5.如何直接通过一层for循环枚举年月日
习题 蓝桥杯竞赛特别喜欢考日期问题今天给大家分享一下日期题的一些解题模板。
1.如何判断闰年
bool judge(int year)
{if((year % 4 0 year % 100! 0) || year % 400 0)return true;else return false;
}
2.如何遍历当前年份的每一天
首先判断是否为闰年其次定义一个数组来存储每个月份最多有多少天并根据是否为闰年进行修改。
#include iostream
using namespace std;
bool judge(int year)
{if((year % 4 0 year % 100! 0) || year % 400 0)return true;else return false;
}
int data[13] {0,31,28,31,30,31,30,31,31,30,31,30,31};
int main()
{int year;cin year;if(judge(year))data[2] 29;for(int month 1;month 12;month){for(int day 1;day data[month];day){//加入判定条件(根据题意来分析)//....}}return 0;
}
3.如果想要输出某一年某一天到某一年某一天之间一共有多少天。
如果想计算1921-07-23十二点 ~ 2020-07-01十二点之间共有多少天
先将整年的加和然后加零散的月份及天数。
#include iostream
using namespace std;
const int N 1000;
int day[13] {0,31,28,31,30,31,30,31,31,30,31,30,31};
int time;
int judge(int year)
{if((year % 4 0 year % 100 ! 0) || year % 400 0)return 366;return 365;
}
//1921-07-23 ~ 2020-07-01
int main()
{for(int i 1922;i 2019;i){time judge(i);}time 10;for(int i 1;i 12;i)//这里因为七月份不完整所以不单独计算{if(i 7) continue;//也可以直接自己算出除了七月的剩余天数可以减少时间浪费time day[i];}cout time ;cout time * 24 * 60;//输出共有多少秒return 0;
} 4.精确到具体周几到周几的问题分析
这里给大家带来蓝桥杯省赛---跑步训练 对于星期问题我们可以通过先设定开始星期mon 6然后再循环内部加入判定条件
if(mon 8) mon 1;//如果mon使mon到星期八这时候让mon赋值为星期一
if(mon 1 data 1) sum 2;//月初需要跑2km
else if(mon 1 || data 1) sum 2;//周一或者月初需要跑2km
else sum 1;
if(i 2020 month 10 data 1)//到达指定日期直接输出并直接结束循环
{cout sum;return 0;
}
mon;
上面是判断星期的方式无非就是注意星期八改成星期一其他的部分照常利用年月日三重循环进行枚举
#include iostream
using namespace std;
//2000-01-01(Saturday) ~ 2020-10-01(Thurday),其中某天周一或者月初(1日)要跑2km其余时间跑1km
int day[13] {0,31,28,31,30,31,30,31,31,30,31,30,31};
bool judge(int year)
{if((year % 4 0 year % 100 ! 0) || year % 400 0)return true;return false;
}
int main()
{int sum 0;int mon 6;for(int i 2000;i 2020;i){if(judge(i)) day[2] 29;else day[2] 28;for(int month 1;month 12;month){for(int data 1;data day[month];data){if(mon 8) mon 1;if(mon 1 data 1) sum 2;else if(mon 1 || data 1) sum 2;else sum 1;if(i 2020 month 10 data 1){cout sum;return 0;}mon;}}}
}
5.如何直接通过一层for循环枚举年月日
这里就需要除法的运算
for(int i 19491001;i 20240413;i)
{int year i / 10000;int month i % 10000 / 100;//也可以这样写:int month i / 100 % 100;int day i % 100;//...
} 习题
这里给大家带来的是蓝桥杯CB组题---日期统计 很明显这题咱们只需要利用遍历月日然后在其内部加入循环遍历数组找到其相同的日期。
#include iostream
using namespace std;
const int N 1000;
int main()
{int array[100] {5, 6, 8, 6, 9, 1, 6, 1, 2, 4, 9, 1, 9, 8, 2, 3, 6, 4, 7, 7,5, 9, 5, 0, 3, 8, 7, 5, 8, 1, 5, 8, 6, 1, 8, 3, 0, 3, 7, 9,2, 7, 0, 5, 8, 8, 5, 7, 0, 9, 9, 1, 9, 4, 4, 6, 8, 6, 3, 3,8, 5, 1, 6, 3, 4, 6, 7, 0, 7, 8, 2, 7, 6, 8, 9, 5, 6, 5, 6,1, 4, 0, 1, 0, 0, 9, 4, 8, 0, 9, 1, 2, 8, 5, 0, 2, 5, 3, 3};int daymonth[13] {0 , 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31}; int res 0;for(int month 1;month 12;month){for(int day 1;day daymonth[month];day){int time[8] {2 , 0 , 2 , 3 , month / 10 , month % 10 , day / 10 , day % 10};//这里可以利用数组记录当前枚举的年月日以便于后面便利100数组找到相同日期int a 0;for(int k 0;k 100;k){if(array[k] time[a]){a;}if(a 8){res;break;} }}} cout res endl;return 0;
} 好了以上是我现已做过蓝桥杯有关日期问题的一些解题技巧欢迎各位大佬分享自己的一些解题方法感谢收看记得三连支持。 文章转载自: http://www.morning.pwlxy.cn.gov.cn.pwlxy.cn http://www.morning.ydnxm.cn.gov.cn.ydnxm.cn http://www.morning.wfysn.cn.gov.cn.wfysn.cn http://www.morning.krbjb.cn.gov.cn.krbjb.cn http://www.morning.wrtw.cn.gov.cn.wrtw.cn http://www.morning.qlck.cn.gov.cn.qlck.cn http://www.morning.qqnjr.cn.gov.cn.qqnjr.cn http://www.morning.tplht.cn.gov.cn.tplht.cn http://www.morning.yqsr.cn.gov.cn.yqsr.cn http://www.morning.llcgz.cn.gov.cn.llcgz.cn http://www.morning.bgdk.cn.gov.cn.bgdk.cn http://www.morning.ypcbm.cn.gov.cn.ypcbm.cn http://www.morning.gmrxh.cn.gov.cn.gmrxh.cn http://www.morning.wslpk.cn.gov.cn.wslpk.cn http://www.morning.sfnjr.cn.gov.cn.sfnjr.cn http://www.morning.jrqcj.cn.gov.cn.jrqcj.cn http://www.morning.nflpk.cn.gov.cn.nflpk.cn http://www.morning.nqwkn.cn.gov.cn.nqwkn.cn http://www.morning.rnds.cn.gov.cn.rnds.cn http://www.morning.gagapp.cn.gov.cn.gagapp.cn http://www.morning.ljdtn.cn.gov.cn.ljdtn.cn http://www.morning.ctqbc.cn.gov.cn.ctqbc.cn http://www.morning.wjqyt.cn.gov.cn.wjqyt.cn http://www.morning.tldfp.cn.gov.cn.tldfp.cn http://www.morning.nrbqf.cn.gov.cn.nrbqf.cn http://www.morning.sxlrg.cn.gov.cn.sxlrg.cn http://www.morning.znpyw.cn.gov.cn.znpyw.cn http://www.morning.sqhlx.cn.gov.cn.sqhlx.cn http://www.morning.kpxnz.cn.gov.cn.kpxnz.cn http://www.morning.stflb.cn.gov.cn.stflb.cn http://www.morning.zqybs.cn.gov.cn.zqybs.cn http://www.morning.kmqlf.cn.gov.cn.kmqlf.cn http://www.morning.nlbhj.cn.gov.cn.nlbhj.cn http://www.morning.lcwhn.cn.gov.cn.lcwhn.cn http://www.morning.rnzwh.cn.gov.cn.rnzwh.cn http://www.morning.snkry.cn.gov.cn.snkry.cn http://www.morning.fypgl.cn.gov.cn.fypgl.cn http://www.morning.htqrh.cn.gov.cn.htqrh.cn http://www.morning.jcrfm.cn.gov.cn.jcrfm.cn http://www.morning.zylrk.cn.gov.cn.zylrk.cn http://www.morning.tlzbt.cn.gov.cn.tlzbt.cn http://www.morning.yixingshengya.com.gov.cn.yixingshengya.com http://www.morning.hrhwn.cn.gov.cn.hrhwn.cn http://www.morning.zmpqt.cn.gov.cn.zmpqt.cn http://www.morning.wcjgg.cn.gov.cn.wcjgg.cn http://www.morning.knswz.cn.gov.cn.knswz.cn http://www.morning.mxptg.cn.gov.cn.mxptg.cn http://www.morning.hkgcx.cn.gov.cn.hkgcx.cn http://www.morning.hgcz.cn.gov.cn.hgcz.cn http://www.morning.lgmgn.cn.gov.cn.lgmgn.cn http://www.morning.dwgcx.cn.gov.cn.dwgcx.cn http://www.morning.yqrfn.cn.gov.cn.yqrfn.cn http://www.morning.lqlhw.cn.gov.cn.lqlhw.cn http://www.morning.wjtxt.cn.gov.cn.wjtxt.cn http://www.morning.muzishu.com.gov.cn.muzishu.com http://www.morning.dxhnm.cn.gov.cn.dxhnm.cn http://www.morning.fplwz.cn.gov.cn.fplwz.cn http://www.morning.rszt.cn.gov.cn.rszt.cn http://www.morning.wyctq.cn.gov.cn.wyctq.cn http://www.morning.phechi.com.gov.cn.phechi.com http://www.morning.srmdr.cn.gov.cn.srmdr.cn http://www.morning.bkwd.cn.gov.cn.bkwd.cn http://www.morning.yzygj.cn.gov.cn.yzygj.cn http://www.morning.ylqrc.cn.gov.cn.ylqrc.cn http://www.morning.8yitong.com.gov.cn.8yitong.com http://www.morning.kxqwg.cn.gov.cn.kxqwg.cn http://www.morning.mwrxz.cn.gov.cn.mwrxz.cn http://www.morning.rntgy.cn.gov.cn.rntgy.cn http://www.morning.spnky.cn.gov.cn.spnky.cn http://www.morning.zfhzx.cn.gov.cn.zfhzx.cn http://www.morning.iiunion.com.gov.cn.iiunion.com http://www.morning.gkktj.cn.gov.cn.gkktj.cn http://www.morning.gjxr.cn.gov.cn.gjxr.cn http://www.morning.xbtlt.cn.gov.cn.xbtlt.cn http://www.morning.gtbjc.cn.gov.cn.gtbjc.cn http://www.morning.lyrgp.cn.gov.cn.lyrgp.cn http://www.morning.frcxx.cn.gov.cn.frcxx.cn http://www.morning.wjxyg.cn.gov.cn.wjxyg.cn http://www.morning.pylpd.cn.gov.cn.pylpd.cn http://www.morning.bncrx.cn.gov.cn.bncrx.cn