hdu 4515 Little Q series story-the farthest distance in the world

topic

I need to commemorate the question of the past date. Thank you for several sets of test data.

Test data for addition: 38 39 282 283 7 8 Test data for subtraction: 52 87345 24 23 100000

The answer is tested in Excel, mainly because many detailed questions need to be considered.

#include<iostream>
#include <algorithm>
#include <set>
#include <cstdio>
using namespace std;
int md[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int leap(int n)
{
    if((n%4==0&&n%100!=0)||(n%400==0))
        return 1;
    return 0;
}
void fun1(int d)
{
    if(d<=7) printf("2013/03/%02d ",24+d);
    else{
        d = d-7;
        int year = 2013,month = 4;
        int tmp,flag= 0;
        while(d>0)
        {
            tmp = d;
            if(month == 2&&flag==1&&d-md[month]-1>0)
                d = d-md[month++]-1;
            else if(d-md[month]>0)
                d = d-md[month++];
            else break;

            if(month>12){
                month = 1;
                year++;
                if(leap(year)==1)
                    flag = 1;
                else flag = 0;
            }
        }
        printf("%d/%02d/%02d ",year,month,tmp);
    }
}
void fun2(int d)
{
    if(d<24) printf("2013/03/%02d\n",24-d);
    else{
        d = d-24;
        int year=2013,month=2;
        int flag = 0,tmp;

        while(d>0)
        {
            if(month==2&&flag==1&&d-md[month]-1>=0)
                d = d-md[month--]-1;
            else if(d-md[month]>=0)
                d = d-md[month--];
            else break;
            if(month<1)
            {
                year--;
                if(leap(year)==1) flag=1;
                else flag=0;
                month = 12;
            }
        }
        printf("%d/%02d/%02d\n",year,month,md[month]-d);
    }
}
int main()
{
    int T,d;cin>>T;
    while(T--)
    {
        cin>>d;
        fun1(d);
        fun2(d);
    }
    return 0;
}

 

Guess you like

Origin blog.csdn.net/qie_wei/article/details/88659960