#38553: WA (line:13) 您的答案為: 294796 正確答案為: 294795


abc092049061299@gmail.com (ㄓㄓㄓ)

學校 : 不指定學校
編號 : 181570
來源 : [118.168.14.99]
最後登入時間 :
2024-12-04 01:03:12
a263. 日期差幾天 -- 板橋高中練習題 | From: [140.138.242.111] | 發表日期 : 2023-12-06 18:45

#include <iostream>
#include <cstdlib>
#include <algorithm>
using namespace std;
bool is_leap_year(int year) {
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
return true;
else
return false;
}
 
int main()
{
int year1, month1, day1, year2, month2, day2;
int month[13] = { 0, 31,28,31,30,31,30,31,31,30,31,30,31 };
while (cin >> year1 >> month1 >> day1 >> year2 >> month2 >> day2) {
if (year2 > year1 || (year2 == year1 && month2 > month1) || (year2 == year1 && month2 == month1 && day2 > day1)) {
swap(year1, year2);
swap(month1, month2);
swap(day1, day2);
}
 
 
int output = 0;
 
while (year1 - year2 > 1) {
if (is_leap_year(year2))
output += 366;
else
output += 365;
year2++;
}
 
output = output + day1 - day2;
if (is_leap_year(year2) && month2 > 2)
output++;
while (year1 != year2 || month1 != month2) {
if (month2 == 2) {
if (is_leap_year(year2))
output += 29;
else
output += 28;
month2++;
continue;
}
output += month[month2];
month2++;
if (month2 == 13) {
month2 = 1;
year2++;
}
}
cout << output << endl;
}
return 0;
}
 
#38577: Re: WA (line:13) 您的答案為: 294796 正確答案為: 294795


abc092049061299@gmail.com (ㄓㄓㄓ)

學校 : 不指定學校
編號 : 181570
來源 : [118.168.14.99]
最後登入時間 :
2024-12-04 01:03:12
a263. 日期差幾天 -- 板橋高中練習題 | From: [140.138.242.111] | 發表日期 : 2023-12-08 11:12

#include
#include
#include
using namespace std;
bool is_leap_year(int year) {
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
return true;
else
return false;
}
 
int main()
{
int year1, month1, day1, year2, month2, day2;
int month[13] = { 0, 31,28,31,30,31,30,31,31,30,31,30,31 };
while (cin >> year1 >> month1 >> day1 >> year2 >> month2 >> day2) {
if (year2 > year1 || (year2 == year1 && month2 > month1) || (year2 == year1 && month2 == month1 && day2 > day1)) {
swap(year1, year2);
swap(month1, month2);
swap(day1, day2);
}
 
 
int output = 0;
 
while (year1 - year2 > 1) {
if (is_leap_year(year2))
output += 366;
else
output += 365;
year2++;
}
 
output = output + day1 - day2;
if (is_leap_year(year2) && month2 > 2)
output++;
while (year1 != year2 || month1 != month2) {
if (month2 == 2) {
if (is_leap_year(year2))
output += 29;
else
output += 28;
month2++;
continue;
}
output += month[month2];
month2++;
if (month2 == 13) {
month2 = 1;
year2++;
}
}
cout << output << endl;
}
return 0;
}

已找到錯

 
ZeroJudge Forum