题目描述
ac代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void getDate(int &year,int &month,int &day,string s){
int flag = 0;
for(int i = 0;i < s.length();i++){
if(flag == 0&&s[i]!='-'){
year = year*10 + (s[i]-'0');
}else if(flag==1 && s[i]!='-'){
month = month*10+(s[i]-'0');
}else if(flag == 2&& s[i]!='-'){
day = day*10+(s[i]-'0');
}
if(s[i]=='-'){
flag++;
}
}
}
void getTime(int &h,int &m,int &second,string s){
int flag = 0;
for(int i = 0;i < s.length();i++){
if(flag == 0&&s[i]!=':'){
h = h*10 + (s[i]-'0');
}else if(flag==1 && s[i]!=':'){
m = m*10+(s[i]-'0');
}else if(flag == 2&& s[i]!=':'){
second = second*10+(s[i]-'0');
}
if(s[i]==':'){
flag++;
}
}
}
bool judgeYear(int year){
if(year%4==0 && year%100!=0 || year%400==0){
return true;
}
else{
return false;
}
}
int getMonthToDay(int year,int month,bool flag){
int day = 0;
if(month == 1){
return 0;
}else if(month == 2){
return 31;
}else{
if(month == 3){
day = 59;
}else if(month == 4){
day = 90;
}else if(month == 5){
day = 120;
}else if(month == 6){
day = 151;
}else if(month == 7){
day = 181;
}else if(month == 8){
day = 212;
}else if(month == 9){
day = 243;
}else if(month == 10){
day = 273;
}else if(month == 11){
day = 304;
}else if(month == 12){
day = 334;
}
if(flag){
day++;
}
return day;
}
}
int main(){
string data1;
string time1;
string data2;
string time2;
int year1,month1,day1,hour1,min1,second1;
int year2,month2,day2,hour2,min2,second2;
cin>>data1>>time1>>data2>>time2;
year1 = 0;
month1=0;
day1=0;
hour1=0;
min1=0;
second1=0;
year2 = 0;
month2=0;
day2=0;
hour2=0;
min2=0;
second2=0;
ll differYear = 0;
ll differMonth = 0;
ll differDay = 0;
getDate(year1,month1,day1,data1);
getDate(year2,month2,day2,data2);
getTime(hour1,min1,second1,time1);
getTime(hour2,min2,second2,time2);
differYear = year2-year1;
bool Flag1 = judgeYear(year1);
bool Flag2 = judgeYear(year2);
if(differYear!=0){
for(int i = year1;i < year2;i++){
if(judgeYear(i)){
differDay += 366;
}else{
differDay += 365;
}
}
}
int tempday1;
int tempday2;
tempday1 = getMonthToDay(year1,month1,Flag1)+day1;
tempday2 = getMonthToDay(year2,month2,Flag2)+day2;
differDay += (tempday2-tempday1);
ll differSecond;
int tempsecond1;
int tempsecond2;
ll ans;
tempsecond1 = hour1*60*60+min1*60+second1;
tempsecond2 = hour2*60*60+min2*60+second2;
differSecond = differDay*24*60*60+tempsecond2-tempsecond1;
ans = differSecond*1000;
cout<<ans<<endl;
return 0;
}