Next Date 求下一天的日期

来源:互联网 发布:单片机编程题 编辑:程序博客网 时间:2024/05/07 19:15
没事做,写着玩玩
#include <cstdio>#include <iostream>using namespace std;struct Date{    int y, m, d;};int pm[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};bool isRunnian(int y){    if(y % 4 != 0) return 0;    else{        if(y%100 == 0 && y%400 != 0) return 0;        else return 1;    }}int main(){    Date date;    while(scanf("%d %d %d", &date.y, &date.m, &date.d) != EOF){        if(isRunnian(date.y)) pm[2] = 29;        else pm[2] = 28;        if(date.m < 1 || date.m > 12){            puts("imput error");            continue;        }        if(date.d < 1 || date.d > pm[date.m]){            puts("imput error");            continue;        }        if(date.m == 12 && date.d == 31){            printf("%d 1 1\n", date.y+1);        }        else if(date.d == pm[date.m]){            printf("%d %d %d\n", date.y, date.m+1, 1);        }        else printf("%d %d %d\n", date.y, date.m, date.d+1);    }    return 0;}

0 0
原创粉丝点击