2 lchad lchad 于 2014.02.28 19:21 提问

做过了之后提示 Output Limit Exceeded 输入多组数据

#include
using namespace std;

int isLeapYear(int year);

int getSum(int year, int rest);

int getRest(int year, int month, int day);

int main(void)
{
unsigned int year;
unsigned int month;
unsigned int day;
char fowardslash1;
char fowardslash2;
int sum = 0;
int rest = 0;
int x;
while(cin >> x)
{
cin >> year;
cin >> fowardslash1;
cin >> month;
cin >> fowardslash2;
cin >> day;

    rest = getRest(year, month, day);

    sum = getSum(year, rest);

    char *week[7] = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};


    cout << week[sum] << endl;

}

system("PAUSE");
return 0;

}

int isLeapYear(int year)
{
int flag;
if(year % 4 == 0)

    if(year % 100)

        if(year % 400 != 0)
            flag = 0;
        else
            flag = 1;
        else
            flag = 1;
        else
            flag = 0;
return flag;

}

int getSum(int year, int rest)
{
int normal[13] = {365, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int leap[13] = {366, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int sum = 0;
while(year - 1899)
{
if(year % 4 == 0)

        if(year % 100)

            if(year % 400 != 0)

                sum += normal[0];
            else
                sum += leap[0];
            else
                sum += leap[0];
            else
                sum += normal[0];

    year--;
}
sum += rest;
sum = sum % 7;

return sum;

}

int getRest(int year, int month, int day)
{
int normal[13] = {365, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int leap[13] = {366, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int i;
int rest = 0;
if(!isLeapYear(year))
{
for(i = 1; i < month-1; i++)
{
rest += normal[i];
}
}
else
{
for(i = 1; i < month-1; i++)
{
rest += leap[i];
}
}
rest += day;

return rest; 

}

Csdn user default icon
上传中...
上传图片
插入图片