#9851: 找不到錯誤


song856854132 (Steve)

學校 : 國立嘉義高級中學
編號 : 48007
來源 : [49.218.98.193]
最後登入時間 :
2017-11-30 21:24:33
a263. 日期差幾天 -- 板橋高中練習題 | From: [73.12.0.148] | 發表日期 : 2015-05-18 02:48

我的方法是把兩個日期各換算成總日數(從1年1 月1 日),在相減

#include <cmath>
#include <iostream>

using namespace std;

int main()
{
    int a[2][3];
    while (cin>>a[0][0]>>a[0][1]>>a[0][2]>>a[1][0]>>a[1][1]>>a[1][2])
    {

        int x=0,y=0,coun_1=0,coun_2=0,day_1=0,month_1=0,day_2=0,month_2=0;
        for (x=1;x<a[0][0];x++)
        {
            if ((x%4==0&&x%100!=0)||x%400==0)
            {
                coun_1++;
            }
        }
        x=0;
        if ((a[0][0]%4==0&&a[0][0]%100!=0)||a[0][0]%400==0)
        {
            for(x=1;x<a[0][1];x++)
            {
                if (0<x&&x<8)
                {
                    month_1+=((x%2!=0)?31:30);
                }
                if (7<x&&x<13)
                {
                    month_1+=((x%2==0)?31:30);
                }
            }
            if (a[0][1]>2)
            {
                month_1=month_1-2;
            }
            else
            {
                month_1=month_1-0;
            }
        }
        else
        {
            for(x=1;x<a[0][1];x++)
            {
                if (0<x&&x<8)
                {
                    month_1+=((x%2!=0)?31:30);
                }
                if (7<x&&x<13)
                {
                    month_1+=((x%2==0)?31:30);
                }
            }
            if (a[0][1]>2)
            {
                month_1=month_1-2;
            }
            else
            {
                month_1=month_1-0;
            }
        }
        day_1=365*(a[0][0]-1)+coun_1+month_1+a[0][2];


        for (y=1;y<a[1][0];y++)
        {
            if ((y%4==0&&y%100!=0)||y%400==0)
            {
                coun_2++;
            }
        }
        y=0;
        if ((a[1][0]%4==0&&a[1][0]%100!=0)||a[1][0]%400==0)
        {
            for(y=1;y<a[1][1];y++)
            {
                if (0<y&&y<8)
                {
                    month_2+=((y%2!=0)?31:30);
                }
                if (7<y&&y<13)
                {
                    month_2+=((y%2==0)?31:30);
                }
            }
            if (a[1][1]>2)
            {
                month_2=month_2-2;
            }
            else
            {
                month_2=month_2-0;
            }
        }
        else
        {
            for(y=1;y<a[1][1];y++)
            {
                if (0<y&&y<8)
                {
                    month_2+=((y%2!=0)?31:30);
                }
                if (7<y&&y<13)
                {
                    month_2+=((y%2==0)?31:30);
                }
            }
            if (a[1][1]>2)
            {
                month_2=month_2-2;
            }
            else
            {
                month_2=month_2-0;
            }
        }

        day_2=365*(a[1][0]-1)+coun_2+month_2+a[1][2];

        cout << day_1-day_2<<endl;

    }


    return 0;
}

 
#9852: Re:找不到錯誤


song856854132 (Steve)

學校 : 國立嘉義高級中學
編號 : 48007
來源 : [49.218.98.193]
最後登入時間 :
2017-11-30 21:24:33
a263. 日期差幾天 -- 板橋高中練習題 | From: [73.12.0.148] | 發表日期 : 2015-05-18 02:49

我的方法是把兩個日期各換算成總日數(從1年1 月1 日),在相減

#include
#include

using namespace std;

int main()
{
    int a[2][3];
    while (cin>>a[0][0]>>a[0][1]>>a[0][2]>>a[1][0]>>a[1][1]>>a[1][2])
    {

        int x=0,y=0,coun_1=0,coun_2=0,day_1=0,month_1=0,day_2=0,month_2=0;
        for (x=1;x        {
            if ((x%4==0&&x%100!=0)||x%400==0)
            {
                coun_1++;
            }
        }
        x=0;
        if ((a[0][0]%4==0&&a[0][0]%100!=0)||a[0][0]%400==0)
        {
            for(x=1;x            {
                if (0                {
                    month_1+=((x%2!=0)?31:30);
                }
                if (7                {
                    month_1+=((x%2==0)?31:30);
                }
            }
            if (a[0][1]>2)
            {
                month_1=month_1-2;
            }
            else
            {
                month_1=month_1-0;
            }
        }
        else
        {
            for(x=1;x            {
                if (0                {
                    month_1+=((x%2!=0)?31:30);
                }
                if (7                {
                    month_1+=((x%2==0)?31:30);
                }
            }
            if (a[0][1]>2)
            {
                month_1=month_1-2;
            }
            else
            {
                month_1=month_1-0;
            }
        }
        day_1=365*(a[0][0]-1)+coun_1+month_1+a[0][2];


        for (y=1;y        {
            if ((y%4==0&&y%100!=0)||y%400==0)
            {
                coun_2++;
            }
        }
        y=0;
        if ((a[1][0]%4==0&&a[1][0]%100!=0)||a[1][0]%400==0)
        {
            for(y=1;y            {
                if (0                {
                    month_2+=((y%2!=0)?31:30);
                }
                if (7                {
                    month_2+=((y%2==0)?31:30);
                }
            }
            if (a[1][1]>2)
            {
                month_2=month_2-2;
            }
            else
            {
                month_2=month_2-0;
            }
        }
        else
        {
            for(y=1;y            {
                if (0                {
                    month_2+=((y%2!=0)?31:30);
                }
                if (7                {
                    month_2+=((y%2==0)?31:30);
                }
            }
            if (a[1][1]>2)
            {
                month_2=month_2-2;
            }
            else
            {
                month_2=month_2-0;
            }
        }

        day_2=365*(a[1][0]-1)+coun_2+month_2+a[1][2];

        cout << day_1-day_2<
    }


    return 0;
}

第 1 測資點(0%): WA (line:2)
答案不正確
您的答案為: 538319 正確答案為: 538320 



 
ZeroJudge Forum