Sicily 1814日期计算问题

#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main()
{
	int test;
	cin >> test;
	while(test--){
		string str1,str2;
		cin >> str1 >> str2;
		int year1=0,year2=0,mon1=0,mon2=0,day1=0,day2=0;
		for(int i=0; i < 4; i++){
			year1=year1*10+str1[i]-'0';
			year2=year2*10+str2[i]-'0';
		}
		for(int i=5; i < 7; i++){
			mon1=mon1*10+str1[i]-'0';
			mon2=mon2*10+str2[i]-'0';
		}
		for(int i=8; i < 10; i++){
			day1=day1*10+str1[i]-'0';
			day2=day2*10+str2[i]-'0';
		}
		//cout << year1 << " " << year2 << " " << mon1 << " " << mon2 << " " << day1 << " " << day2 << endl;
		long long d1=0,d2=0;
		for(int i=1; i < year1; i++){
			if((i%4==0&&i%100!=0)||i%400==0) d1+=366;
			else d1+=365;
		}
		for(int i=1; i < mon1; i++){
			if(i==1||i==3||i==5||i==7||i==8||i==10||i==12) d1+=31;
			else if(i==4||i==6||i==9||i==11) d1+=30;
			else if(i==2){
				if((year1%4==0&&year1%100!=0)||year1%400==0) d1+=29;
				else d1+=28;
			}
		}
		d1+=day1;
		for(int i=1; i < year2; i++){
			if((i%4==0&&i%100!=0)||i%400==0) d2+=366;
			else d2+=365;
		}
		for(int i=1; i < mon2; i++){
			if(i==1||i==3||i==5||i==7||i==8||i==10||i==12) d2+=31;
			else if(i==4||i==6||i==9||i==11) d2+=30;
			else if(i==2){
				if((year2%4==0&&year2%100!=0)||year2%400==0) d2+=29;
				else d2+=28;
			}
		}
		d2+=day2;
		//cout << d1 << " " << d2 << endl;
		long long cha=d1-d2;
		if(cha > 0) cout << cha << endl;
		else cout << (-1)*cha << endl;
	}	
} 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值