日期处理 日期数组方便查询每个月的天数 1int days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; 判断闰年被400整除 或者 被4整除的同时不被100整除 123456int is_leap(int year){ if (year % 4 == 0 && year % 100 || year % 400 == 0) return 1; return 0;} 每个月的天数主要是需要判断闰年和月份的情况 123456int get_month_day(int year, int month){ int res = days[month]; if (month == 2 && is_leap(year)) res += 1; return res;} 每年的天数123456int get_year_day(int year){ int res = 365; if (is_leap(year)) res += 1; return res;} 基础知识 #日期 日期处理 http://pikachuxpf.github.io/posts/3381e20e/ 作者 Pikachu_fpx 发布于 2024年3月13日 许可协议 树状数组 上一篇 简单配置VScodeC or Cpp环境 下一篇 Please enable JavaScript to view the comments