4 条题解
-
1马睿 (2024sng28) LV 9 @ 2024-12-20 19:57:36
菜就多练
#include<bits/stdc++.h> using namespace std; int sy,sm,sd,ey,em,ed,ans,m[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; int main() { cin>>sy>>sm>>sd>>ey>>em>>ed; while(sy!=ey||sm!=em||sd!=ed){ ans++; sd++; if(sy%4==0&&sy%100!=0||sy%400==0)m[2] = 29; else m[2] = 28; if(sd>m[sm]){ sd = 1; sm++; } if(sm>12){ sm = 1; sy++; } } cout<<ans; return 0; }
-
02023-1-30 19:32:25@
/********************************* 备注: *********************************/ #include<map> #include<list> #include<stack> #include<queue> #include<cmath> #include<queue> #include<stack> #include<deque> #include<math.h> #include<cstdio> #include<string> #include<vector> #include<cstring> #include<fstream> #include<stdio.h> #include<sstream> #include<iomanip> #include<iostream> #include<string.h> #include<algorithm> #include<bits/stdc++.h> using namespace std; #define in int #define ch char #define lo long #define fl float #define sh short #define db double #define str string #define ll long long #define ld long double #define lli long long int const int N =1e5+10; const int INF =0x3f3f3f3f; int lapeyear(int year2)//闰年判断函数 { if ((year2 % 400 == 0) || (year2 % 4 == 0 && year2 % 100 != 0)) return 1; else return 0; } int years1(int year1, int year2)//计算两年间的天数 { int d = 0, i, r = 0, z = 0; if (year1 < year2) { for (i = year1 + 1; i < year2; i++) { if (lapeyear(i))r++;//两年之间有多少个闰月 } d = (year2 - year1 - 1) * 365 + r; } else { for (i = year2 + 1; i < year1; i++) { if (lapeyear(i))r++;//两年之间有多少个闰月 } d = (year1 - year2 - 1) * 365 + r; } return d; } int months2(int year, int month, int date)//计算到年初日差的函数 { int i, d = 0; int years[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 }; if (lapeyear(year))years[1] = 29; for (i = 0; i < month - 1; i++) { d += years[i]; } d += date; return d; } int months1(int year, int month, int date)//计算到年底日差的函数 { int i, d = 0; int years[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 }; if (lapeyear(year))years[1] = 29; for (i = 11; i > month - 1; i--) { d += years[i]; } d = d + years[month - 1] - date; return d; } int main() { int year1, year2, month1, month2, date1, date2; int d = 0, i, m = 0; int x1, x2;//记录两个日期分别到年初和年底的天数 int years[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 }; cin >> year1 >> month1 >> date1 >> year2 >> month2 >> date2; if (year1 == year2)//大前提,同年时 { if (lapeyear(year1))years[1] = 29; if (month1 == month2)d = date1 > date2 ? date1 - date2 : d = date2 - date1;//同年同月 if (month1 != month2)//同年不同月 { //计算方法为求出两月之前的天数,然后求前一个月剩余的天数和后一个月已经开始的天数 if (month1 < month2) { { for (i = month1; i < month2 - 1; i++) { m += years[i]; } } d = years[month1 - 1] - date1; d += m + date2; } else { for (i = month2; i > month1 - 1; i++) { m += years[i]; } d = years[month2 - 1] - date2; d += m + date1; } } } else//求不同年的任意日期的天数差 { if (year1 > year2) { x1 = months1(year2, month2, date2);//x1为到年底的日差,x2为到年初的日差 x2 = months2(year1, month1, date1); d = years1(year2, year1); d += x1 + x2; } else { x2 = months2(year2, month2, date2); x1 = months1(year1, month1, date1); d = years1(year1, year2); d += x1 + x2; } } cout << d; return 0; }
-
-22024-5-23 19:54:36@
简单易懂的代码
#include <bits/stdc++.h> using namespace std; int a,b,c,d,e,f,sum = 0; int main(){ cin >> a >> b >> c >> d >> e >> f; while(!(a == d && b == e && c == f)){ c++; sum++; if((b == 1 || b == 3 || b == 5 || b == 7 || b == 8 || b == 10 || b == 12) && c == 32){ c = 1; b++; } if((b == 4 || b == 6 || b == 9 || b == 11) && c == 31){ c = 1; b++; } if(b == 2 && ((a % 100 == 0 && a % 400 == 0) || (a % 100 != 0 && a % 4 == 0)) && c == 30){ c = 1; b++; } if(b == 2 && (!((a % 100 == 0 && a % 400 == 0) || (a % 100 != 0 && a % 4 == 0))) && c == 29){ c = 1; b++; } if(b == 13){ b = 1; a++; } } cout << sum << endl; return 0; }
-
-22024-4-26 17:50:15@
#include<map> #include<lis> #include<stack> #include<queue> #include<cmath> #include<queue> #include<stack> #include<deque> #include<math.h> #include<cstdio> #include<string> #include<vector> #include<cstring> #include<fstream> #include<stdio.h> #include<sstream> #include<iomanip> #include<iostream> #include<string.h> #include<algorithm> #include<bits/stdc++.h> using namespace std; #define in int #define ch char #define lo long #define fl float #define sh short #define db double #define str string #define ll long long #define ld long double #define lli long long int const int N =1e5+10; const int INF =0x3f3f3f3f; int lapeyear(int year2)//闰年判断函数 { if ((year2 % 400 == 0) || (year2 % 4 == 0 && year2 % 100 != 0)) return 1; else return 0; } int years1(int year1, int year2)//计算两年间的天数 { int d = 0, i, r = 0, z = 0; if (year1 < year2) { for (i = year1 + 1; i < year2; i++) { if (lapeyear(i))r++;//两年之间有多少个闰月 } d = (year2 - year1 - 1) * 365 + r; } else { for (i = year2 + 1; i < year1; i++) { if (lapeyear(i))r++;//两年之间有多少个闰月 } d = (year1 - year2 - 1) * 365 + r; } return d; } int months2(int year, int month, int date)//计算到年初日差的函数 { int i, d = 0; int years[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 }; if (lapeyear(year))years[1] = 29; for (i = 0; i < month - 1; i++) { d += years[i]; } d += date; return d; } int months1(int year, int month, int date)//计算到年底日差的函数 { int i, d = 0; int years[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 }; if (lapeyear(year))years[1] = 29; for (i = 11; i > month - 1; i--) { d += years[i]; } d = d + years[month - 1] - date; return d; } int main() { int year1, year2, month1, month2, date1, date2; int d = 0, i, m = 0; int x1, x2;//记录两个日期分别到年初和年底的天数 int years[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 }; cin >> year1 >> month1 >> date1 >> year2 >> month2 >> date2; if (year1 == year2)//大前提,同年时 { if (lapeyear(year1))years[1] = 29; if (month1 == month2)d = date1 > date2 ? date1 - date2 : d = date2 - date1;//同年同月 if (month1 != month2)//同年不同月 { //计算方法为求出两月之前的天数,然后求前一个月剩余的天数和后一个月已经开始的天数 if (month1 < month2) { { for (i = month1; i < month2 - 1; i++) { m += years[i]; } } d = years[month1 - 1] - date1; d += m + date2; } else { for (i = month2; i > month1 - 1; i++) { m += years[i]; } d = years[month2 - 1] - date2; d += m + date1; } } } else//求不同年的任意日期的天数差 { if (year1 > year2) { x1 = months1(year2, month2, date2);//x1为到年底的日差,x2为到年初的日差 x2 = months2(year1, month1, date1); d = years1(year2, year1); d += x1 + x2; } else { x2 = months2(year2, month2, date2); x1 = months1(year1, month1, date1); d = years1(year1, year2); d += x1 + x2; }
} cout << d; return 0;
}
- 1
信息
- ID
- 917
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 4
- 标签
- 递交数
- 171
- 已通过
- 82
- 上传者