2 条题解
-
1黄辰飞 (njnu19180237) LV 10 @ 2019-03-31 13:22:53
#include <iostream> using namespace std; class Date { int year; int month; int day; public: void init(int y, int m, int d) { year = y; month = m; day = d; } int isLeapYear() { if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) return 1; else return 0; } int isLeapYear(int i) { if (i % 400 == 0 || (i % 4 == 0 && i % 100 != 0)) return 1; else return 0; } int daytoEnd() { int Month[13] = { 0,31,28 + isLeapYear(),31,30,31,30,31,31,30,31,30,31 }; if (month == 12) return 31 - day; int ans = Month[month] - day; while (month < 12) { ans += Month[month+1]; month++; } return ans; } int GapYearDay(int y) { int ans = 365 * (y - year - 1); for (int i = year + 1; i < y; i++) { if (isLeapYear(i)) ans++; } return ans; } int DaytoBegin() { int Month[13] = { 0,31,28 + isLeapYear(),31,30,31,30,31,31,30,31,30,31 }; if (month == 1) return day; int ans = day; while (month > 1) { ans += Month[month - 1]; month--; } return ans; } }; int main() { int y1, m1, d1, y2, m2, d2; cin >> y1 >> m1 >> d1 >> y2 >> m2 >> d2; Date date1, date2; date1.init(y1, m1, d1); date2.init(y2, m2, d2); cout << date1.daytoEnd() + date1.GapYearDay(y2) + date2.DaytoBegin(); return 0; }
-
02021-02-08 21:18:38@
#include <iostream> using namespace std; int isLeap(int year); int MonthDay(int year, int month); int GoDays(int year,int month,int day); int main() { int year1,month1,day1; int year2,month2,day2; cin>>year1>>month1>>day1; cin>>year2>>month2>>day2; int sum=GoDays(year2,month2,day2); for(int y=year1; y<year2; y++) sum=sum+365+isLeap(y); sum=sum-GoDays(year1,month1,day1); cout<<sum<<endl; // 4600 return 0; } int isLeap(int year) // 返回值1,是; 返回值0,不是。 { int r4=year%4; int r100=year%100; int r400=year%400; if(r400==0 || (r4==0 && r100!=0) ) return 1; // 1600 2000 1988 2020 else return 0; // 2021 2022 2023 } int MonthDay(int year, int month) { int leap=isLeap(year); int day=31; if(month==4 || month==6 || month==9 || month==11) day=30; else if(month==2) day=28+leap; return day; } int GoDays(int year,int month,int day) { int sum=day; for(int m=1; m<month; m++) sum=sum+MonthDay(year,m); return sum; }
- 1
信息
- ID
- 1005
- 难度
- 5
- 分类
- (无)
- 标签
- 递交数
- 470
- 已通过
- 178
- 通过率
- 38%
- 被复制
- 3
- 上传者