鱼C论坛

 找回密码
 立即注册
查看: 3879|回复: 1

求大佬看一下,大佬洪福齐天,夜夜当新郎,全国各地都有丈母娘。

[复制链接]
发表于 2020-1-8 23:14:36 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x

http://codeup.cn/problem.php?cid=100000578&pid=1

  1. #include<iostream>
  2. using namespace std;
  3. int monthDays[13][2] = { {0,0},{31,31},{28,29}, {31,31},{30,30},{31,31},{30,30}, {31,31},{31,31},{30,30},{31,31},{30,30},{31,31} };
  4. string monthRevertArray[13] = {" ", "January","February","March","April","May","June","July","August","September","October","November","December" };
  5. string weekRevertArray[8] = { "","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday" };
  6. int nowYear=2020, nowMonth=01, nowDay=8,nowWeek=3;
  7. string nowWeekString="wednesday";
  8. int monthRevert(string monthString) {
  9.         for (int i = 0; i < 14; i++) {
  10.                 if (monthString == monthRevertArray[i])
  11.                 {       
  12.                         return i;
  13.                 }
  14.         }
  15. }
  16. int weekRevert(string weekString) {
  17.         for (int i = 0; i < 8; i++) {
  18.                 if (weekString == weekRevertArray[i])
  19.                 {
  20.                         return i;
  21.                 }
  22.         }
  23. }
  24. bool IsLeap(int year) {
  25.         return((year % 4 == 0 && year % 100 != 0) || year % 400 == 0);
  26. }
  27. int main() {
  28.         int day,month, year,week,ans=1;
  29.         string monthString, weekString;
  30.         cin >> day >> monthString>>year;
  31.         month = monthRevert(monthString);

  32.         while (year < nowYear|| month < nowMonth || day < nowDay){
  33.                 while (year < nowYear - 1) {
  34.                         if (IsLeap(year)) ans += 366;
  35.                         else ans += 365;
  36.                         year++;
  37.                 }
  38.                 while (year < nowYear || month < nowMonth || day < nowDay) {
  39.                         day++;
  40.                         if(day == monthDays[month][IsLeap(year)] + 1)
  41.                         {
  42.                                 month++;
  43.                                 day = 1;
  44.                         }
  45.                         if (month == 13) {
  46.                                 year++;
  47.                                 month = 1;
  48.                         }
  49.                         ans++;
  50.                 }
  51.         }
  52.        
  53.         week =(nowWeek+ ans % 7)%7;
  54.         weekString = weekRevertArray[week];
  55.         cout << weekString;
  56.         return 0;
  57. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-1-9 16:46:48 | 显示全部楼层
加上注释 ,然后说明问题在哪里
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-1 06:41

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表