文章
6
粉丝
84
获赞
0
访问
3.6k
#include<stdio.h> struct data{ int year; int month; int day; }; int daytab[2][13]={ {0,31,28,31,30,31,30,31,31,30,31,30,31}, {0,31,29,31,30,31,30,31,31,30,31,30,31}, }; int IsLeapYear(int year){ return (year%4==0&&year%100!=0)||year%400==0; } int isValidDate(int year, int month, int day) { //判断日期是否合法 if (year < 1 || month < 1 || month > 12 || day < 1) { return 0; } int daysInMonth[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; if (IsLeapYear(year)) { daysInMonth[2] = 29; } return day <= daysInMonth[month]; } int main() { struct data d; while (~scanf("%d%d%d", &d.year, &d.month, &d.day)) { if(!isValidDate(d.year,d.month,d.day)){ printf("Input error!"); } int number = 0; int row = IsLeapYear(d.year); for (int i = 0; i < d.month; i+...
登录后发布评论
找到错误了,我要气死,错误日期的输出没有写回车