The "title description" gives you two dates and asks how many milliseconds the two dates are.
"Input format" two lines, one date per line, date format guaranteed to "Yyyy-mm-dd hh:mm:ss" this form. The second date time must be greater than the first DateTime. The year of the two date must be the year of 21st century.
An integer representing the number of milliseconds in the output format line.
"Sample input 1" 2000-01-01 00:00:00 2000-01-01 00:00:01
"Sample Output 1" 1000
"Sample input 2" 2000-01-01 00:00:00 2000-11-11 00:00:00
"Sample Output 2" 27216000000
"Sample Interpretation" there used to be a mountain.
"Data range and regulation" for 10% of data, two dates are the same. For 20% of the data, the two dates may differ only by the number of seconds. For 30% of data, two dates may differ in seconds and minutes. For 40% of data, the date of two days must be the same. For 60% of the data, the two dates must be the same year and month. For 80% of data, the year of two dates must be the same. For 100% of the data, two dates must be one day in 21st century, and the second date must be greater than or equal to the first day.
This problem is purely analog, but I thought for an hour, debug an hour still finish AC, so first plan to abandon the pit. Wait for another chance to make up again next time.
The idea is: to find the first date to xxxx-01-01 00:00:00 time is recorded as X1
Find the time of the second date to xxxx-01-01 00:00:00 as X2
Find the year difference between the first date and the second date to change to seconds as X3
Then multiply the value of x3+x2-x1 to *1000, which is the last value.
Attach your own code of error
#include <iostream>#include<string>#include<cstdio>using namespacestd;intnor[]={0, to, -, to, -, to, -, to, to, -, to, -, to};intyesr[]={0, to, in, to, -, to, -, to, to, -, to, -, to};inta[7],b[7];Long Longmiao=0, flag=0, cha=0, sb=0, total=0;Chars;BOOLRinty) { if(Y%4==0&& y% -!=0|| Y% -==0) { return true; } Else { return false; } }Long LongYueintMonthintDayintflag) { intmiao=0; if(flag==1){ for(intI=1; i<month;i++) {Miao+=Yesr[i]; } Day= Day-1; Miao= (miao+day) * -*3600; returnMiao; } Else{ for(intI=1; i<month;i++) {Miao+=Nor[i]; } Miao= (miao+day) * -*3600; returnMiao; }}Long LongNianintYEAR1,intyear2) { intCha=0; for(inti=year1;i<=year2;i++){ if(R (i)) cha+=366; Elsecha+=365; } Cha= Cha *3600; returncha;}intMain () {scanf ("%d-%d-%d%d:%d:%d", &a[1],&a[2],&a[3],&a[4],&a[5],&a[6]); scanf ("%d-%d-%d%d:%d:%d", &b[1],&b[2],&b[3],&b[4],&b[5],&b[6]); if(R (a[1])) flag=1; Elseflag=0; Miao=a[6]+a[5]* -+a[4]*3600+yue (a[2],a[3],flag); Cha=nian (a[1],b[1]); if(R (b[1])) flag=0; Elseflag=0; SB=b[6]+b[5]* -+b[4]*3600+yue (b[2],b[3],flag) *3600; Total= (SB + cha-miao) * +; cout<<total<<Endl; return 0;}
Error code
This is probably the longest simulation I've ever written.
"Analog" date difference