#include\x20\nusing\x20namespace\x20std;\n\nint\x20main()\x20{\n\x20int\x20N;\n\x20cin\x20>>\x20N;\n\x20\n\x20int\x20days[7]\x20=\x20{0};\x20//\x20array\x20to\x20store\x20the\x20count\x20of\x2013th\x20falling\x20on\x20each\x20day\x20of\x20the\x20week\n\x20\n\x20int\x20day\x20=\x200; \x20//\x20represents\x20the\x20current\x20day\x20of\x20the\x20week,\x200-6\x20(0\x20for\x20Monday,\x206\x20for\x20Sunday)\n\x20\n\x20for\x20(int\x20year\x20=\x201900; year\x20<\x201900\x20+\x20N; year++)\x20{\n\x20\x20for\x20(int\x20month\x20=\x201; month\x20<=\x2012; month++)\x20{\n\x20\x20\x20day\x20=\x20(day\x20+\x2013)\x20%\x207; \x20//\x20calculate\x20the\x20day\x20of\x20the\x20week\x20for\x20the\x2013th\x20of\x20the\x20current\x20month\n\x20\x20\x20days[day]++;\x20//\x20increment\x20the\x20count\x20for\x20that\x20day\n\x20\x20\x20\x20//\x20check\x20if\x20the\x20month\x20has\x2030\x20or\x2031\x20days\n\x20\x20\x20if\x20(month\x20==\x204\x20||\x20month\x20==\x206\x20||\x20month\x20==\x209\x20||\x20month\x20==\x2011)\x20{\n\x20\x20\x20\x20day\x20=\x20(day\x20+\x2030)\x20%\x207; \x20//\x20add\x2030\x20days\x20to\x20the\x20current\x20day\n\x20\x20\x20} else\x20if\x20(month\x20==\x202)\x20{\x20//\x20check\x20if\x20it's\x20February\n\x20\x20\x20\x20//\x20check\x20if\x20it's\x20a\x20leap\x20year\n\x20\x20\x20\x20if\x20((year\x20%\x204\x20==\x200\x20&& year\x20%\x20100\x20!=\x200)\x20||\x20(year\x20%\x20400\x20==\x200))\x20{\n\x20\x20\x20\x20\x20day\x20=\x20(day\x20+\x2029)\x20%\x207; \x20//\x20add\x2029\x20days\x20to\x20the\x20current\x20day\n\x20\x20\x20\x20} else\x20{\n\x20\x20\x20\x20\x20day\x20=\x20(day\x20+\x2028)\x20%\x207; \x20//\x20add\x2028\x20days\x20to\x20the\x20current\x20day\n\x20\x20\x20\x20}\n\x20\x20\x20} else\x20{\n\x20\x20\x20\x20day\x20=\x20(day\x20+\x2031)\x20%\x207; \x20//\x20add\x2031\x20days\x20to\x20the\x20current\x20day\n\x20\x20\x20}\n\x20\x20}\n\x20}\n\x20\n\x20//\x20print\x20the\x20count\x20of\x2013th\x20falling\x20on\x20each\x20day\x20of\x20the\x20week\n\x20for\x20(int\x20i\x20=\x200; i\x20<\x207; i++)\x20{\n\x20\x20cout\x20<<\x20days[i]\x20<<\x20"\x20";\n\x20}\n\x20\n\x20return\x200;\n}


原文地址: http://www.cveoy.top/t/topic/pFpJ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录