《演算法筆記》3.4小節——入門模擬->日期處理 問題 E: 日期累加
阿新 • • 發佈:2018-12-14
把握今天,才能擁有明天!
#include <stdio.h> bool run(int aha) { if((aha%4==0&&aha%100!=0)||aha%400==0) return true; else return false; } int main() { int day,year,month,cnt; int n; scanf("%d",&n); int dayofMonth[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}}; for(int j = 0;j < n;j++){ scanf("%d %d %d %d",&year,&month,&day,&cnt); for(int i = cnt;i > 0;i--){ day++; if(day == dayofMonth[month][run(year)] + 1){ month++; day = 1; } if(month == 13){ year++; month = 1; } } printf("%04d-%02d-%02d\n",year,month,day); } return 0; }