1070.今年的第几天?

题目描述:
输入年、月、日,计算该天是本年的第几天。
输入:
包括三个整数年(1<=Y<=3000)、月(1<=M<=12)、日(1<=D<=31)。
输出:
输入可能有多组测试数据,对于每一组测试数据,

输出一个整数,代表Input中的年、月、日对应本年的第几天。
样例输入:

1990 9 20
2000 5 1
样例输出:

263
122

#include<iostream>
using namespace std;
#define ISYEAP(x) x%100!=0 && x%4==0 || x%400==0 ? 1: 0

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
};

struct date{
    int day;
    int month;
    int year;
    void nextday(){
        day++;
        if(day>dayofmonth[month][ISYEAP(year)]){
            month++;
            if(month>12){
                month=1;
                year++;
            }
        }
    }
};

int buf[3001][13][32];

int main(){
    date temp;
    int cnt=0;
    temp.day=1;
    temp.year=0;
    temp.month=1;
    while(temp.year!=3001){
        buf[temp.year][temp.month][temp.day]=cnt;
        temp.nextday();
        cnt++;
    }
    int d,m,y;
    while(cin>>y>>m>>d){
        cout<<buf[y][m][d]-buf[y-1][12][31]<<endl;
    }
    return 0;
}
原文地址:https://www.cnblogs.com/bernieloveslife/p/9736447.html