第一题WA,各种极端都试过了,讨论帖里的例子也都试过

0
0
#include <iostream>
#include<string>
using namespace std;
const string a[12] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
int count(int day_1, int day_2, int month_1, int month_2, int year_1, int year_2)
{
    int y_1, y_2,i,j=0;
    if (month_1 <= 2)
        y_1 = year_1;
    else if (month_1>2)
        y_1 = year_1 + 1;
    if (month_2 < 2)
        y_2 = year_2;
    else if (month_2 > 2)
        y_2 = year_2 + 1;
    else if (month_2 = 2)
    {
        if (day_2 = 29)
            y_2 = year_2 + 1;
        else y_2 = year_2;
    }
    for (i = y_1; i < y_2; i++)
    {
        if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0)
            j++;
    }
    return j;
}
int main()
{
    int t = 0;
    while (t<1 || t>550)
    {
        cin >> t;
    }
    int i=0,j,d,y=0,month_1,month_2,day_1,day_2,year_1,year_2;
    char l;
    string m;
    int *num = new int [t];
    int *month = new int[2 * t];
    int *day = new int[2 * t];
    int *year = new int[2 * t];
    for (i ; i < 2 * t; i++)
    {
        cin >> m >> d >> l >> y;
        for (j = 0; j < 12; j++)
        {
            if (m == a[j])
            {
                month[i] = j + 1;
                break;
            }
        }
        day[i] = d;
        year[i] = y;
        if (y<2000 || y>3000)
        {
            cout << "input wrong!input again:" << endl;
            return 0;
        }
        if ((month[i] == 1 || month[i] == 3 || month[i] == 5 || month[i] == 7 || month[i] == 8 || month[i] == 10 || month[i] == 12) && (day[i]<1 || day[i]>31))
        {
            cout << "input wrong!input again:" << endl;
            return 0;
        }
        else if ((month[i] == 4 || month[i] == 6 || month[i] == 9 || month[i] == 11) && (day[i]<1 || day[i]>30))
        {
            cout << "input wrong!input again:" << endl;
            return 0;
        }
        else if (month[i]==2&&((year[i] % 4 == 0 && year[i] % 100 != 0) || year[i] % 400 == 0) && (day[i]<1 || day[i]>29))
        {
            cout << "input wrong!input again:" << endl;
            return 0;
        }
        else if (month[i]==2&&(year[i] % 4 != 0 || (year[i] % 100 == 0 && year[i] % 400 != 0)) && (day[i]<1 || day[i]>28))
        {
            cout << "input wrong!input again:" << endl;
            return 0;
        }
        if (i % 2 == 1)
        {
            day_1 = day[i - 1];
            day_2 = day[i];
            year_1 = year[i - 1];
            year_2 = year[i];
            month_1 = month[i-1];
            month_2 = month[i];
            while (year_2 < year_1 || ((year_2 == year_1) && (month_2 < month_1)) || ((year_2 == year_1) && (month_2 == month_1) && (day_2 < day_1)))
            {
                cout << "input wrong!input again:" << endl;
                i = i - 1;
                return 0;
            }
            num[i/2] = count(day_1, day_2, month_1, month_2, year_1, year_2);

        }
    }
    for (i = 0; i < t; i++)
    {

        cout << "Case #" << i + 1 << ": " << num[i] << endl;
    }
    return 0;
}

write answer 切换为英文 切换为中文


转发分享