Top

时间差


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e2 + 10;
const int mod = 1e9 + 7;
char Sdate[maxn],Edate[maxn];
bool IsLyear(int year){
return ((year%4==0&&year%100!=0)||year%400==0);
}
int GetDay(int y,int m,int d){
int day=0;
for(int i=1;i<y;i++){
day+=365;
if(IsLyear(i))day++;
}
for(int i=1;i<m;i++){
if(i==1||i==3||i==5||i==7||i==8||i==10||i==12)day+=31;
else if(i==2){
if(IsLyear(y))day+=29;
else day+=28;
}
else day+=30;
}
day+=d;
return day;
}
int Solve(int y1,int m1,int d1,int y2,int m2,int d2){
return GetDay(y2,m2,d2)-GetDay(y1,m1,d1)+1;
}
int main(){
int t;
scanf("%d", &t);
while (t--){
int n;
int day=0;
scanf("%d",&n);
while(n--){
int y1,m1,d1,y2,m2,d2;
scanf("%d/%d/%d",&y1,&m1,&d1);
scanf("%d/%d/%d",&y2,&m2,&d2);
day+=Solve(y1,m1,d1,y2,m2,d2);
}
printf("%d\n",day);
}
return 0;
}
文章版权为Anoyer博客所有,转载请以链接形式标明本文地址