当前位置: 代码迷 >> 综合 >> 《算法笔记》3.4小节——入门模拟-日期处理 问题 B: Day of Week
  详细解决方案

《算法笔记》3.4小节——入门模拟-日期处理 问题 B: Day of Week

热度:71   发布时间:2023-11-18 00:58:10.0

把握今天,才能拥有明天!

#include <cstdio>
#include <cstring>char month[15][20] = { {}, {"January"}, {"February"}, {"March"}, {"April"}, {"May"}, {"June"}, {"July"}, {"August"}, {"September"}, {"October"}, {"November"}, {"December"}
};
char week[15][20] = { {"Monday"}, {"Tuesday"}, {"Wednesday"}, {"Thursday"}, {"Friday"}, {"Saturday"}, {"Sunday"}
};int main()
{int d, y, k;char m[15];while (scanf ("%d %s %d", &d, m, &y) != EOF) {for (int i = 0; i < 13; i++) {if (strcmp (month[i], m) == 0)  k = i;}   if (k == 1 || k == 2) {                      k += 12;y--;}int j = (d + 2 * k + 3 * (k + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7;printf ("%s\n", week[j]);                   }return 0;
}

 

  相关解决方案