首页 > 代码库 > 第几天?(hdu2005)

第几天?(hdu2005)

技术分享

第几天那个代码模板可以保存起来。

#include<stdio.h>
#include<math.h>
#define PI 3.1415927
using namespace std;
int main()
{
    int year,month,day;    
    char a,b,d;
    while(scanf("%d%c%d%c%d%c",&year,&a,&month,&b,&day,&d)!=EOF)
    {
        switch(month)
        {
        case 1:
            day=day;
            break;
        case 2:
            day=31+day;
            break;
        case 3:
            day=31+28+day;
            break;
        case 4:
            day=31+28+31+day;
            break;
        case 5:
            day=31+28+31+30+day;
            break;
        case 6:
            day=31+28+31+30+31+day;
            break;
        case 7:
            day=31+28+31+30+31+30+day;
            break;
        case 8:
            day=31+28+31+30+31+30+31+day;
            break;
        case 9:
            day=31+28+31+30+31+30+31+31+day;
            break;
        case 10:
            day=31+28+31+30+31+30+31+31+30+day;
            break;
        case 11:
            day=31+28+31+30+31+30+31+31+30+31+day;
            break;
        default:
            day=31+28+31+30+31+30+31+31+30+31+30+day;
        }
        if(month>2)
        {
        if(year%100==0)
        {
            if(year%400==0)
            {
                day=day+1;
                printf("%d\n",day);
            }
            else
            {
                printf("%d\n",day);
            }
        }
        else
        {
            if(year%4==0)
            {
                day=day+1;
                printf("%d\n",day);
            }
            else
            {
                printf("%d\n",day);
            }
        }
        }
        else
            printf("%d\n",day);
    }
}

 

第几天?(hdu2005)