#include<iostream>
using namespace std;
int main() {
int a , b , c , d[3] = {0} , i = 0 ;
while ( cin >> a >> b >> c ) {
d[i] = (a-1) / 4 - (a-1) / 100 + (a-1) / 400 - (a-1) / 4000 ;
if ( b == 3 ) d[i] -- ;
if ( b == 2 || b == 6 || b == 7 ) d[i] ++ ;
if ( b == 8 ) d[i] = d[i] + 2 ;
if ( b == 9 || b == 10 ) d[i] = d[i] + 3 ;
if ( b == 11 || b == 12 ) d[i] = d[i] + 4 ;
if ( b > 3 ) {
if ( a % 4 == 0 ) d[i] ++ ;
if ( a % 100 == 0 ) d[i] -- ;
if ( a % 400 == 0 ) d[i] ++ ;
if ( a % 4000 == 0 ) d[i] -- ;
}
d[i] = (a-1)*365 + (b-1)*30 + c + d[i] ; d[2] = d[0] - d[1] ;
if ( i % 2 ) { if (d[2]>0) { cout << d[2] << endl ; } else cout << -d[2] << endl ; i = -1 ; } i ++ ;
}
}
您的答案為: 319180
正確答案為: 319181
#include
using namespace std;
int main() {
int a , b , c , d[3] = {0} , i = 0 ;
while ( cin >> a >> b >> c ) {
d[i] = (a-1) / 4 - (a-1) / 100 + (a-1) / 400 - (a-1) / 4000 ;
if ( b == 3 ) d[i] -- ;
if ( b == 2 || b == 6 || b == 7 ) d[i] ++ ;
if ( b == 8 ) d[i] = d[i] + 2 ;
if ( b == 9 || b == 10 ) d[i] = d[i] + 3 ;
if ( b == 11 || b == 12 ) d[i] = d[i] + 4 ;
if ( b > 3 ) {
if ( a % 4 == 0 ) d[i] ++ ;
if ( a % 100 == 0 ) d[i] -- ;
if ( a % 400 == 0 ) d[i] ++ ;
if ( a % 4000 == 0 ) d[i] -- ;
}
d[i] = (a-1)*365 + (b-1)*30 + c + d[i] ; d[2] = d[0] - d[1] ;
if ( i % 2 ) { if (d[2]>0) { cout << d[2] << endl ; } else cout << -d[2] << endl ; i = -1 ; } i ++ ;
}
}
您的答案為: 319180
正確答案為: 319181
把 b>3 改 b>2