hdoj1201简单题、模拟题

本文深入探讨了编程技巧与算法应用,从基础到高级,包括数据结构、算法设计、测试与版本控制等多个方面,旨在帮助开发者提升技能,解决实际问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

测试数据:

10
1980-02-29
-1
1988-03-03
6574
1987-03-03
6575
1970-03-03
6575
1988-02-02
6575
1987-02-02
6575
1970-02-02
6574
1988-02-28
6575
1970-02-28
6574
1987-02-28
6575
Press any key to continue . . .

#include<iostream>//注意找规律,不要一天一天的模拟
#include<string>
using namespace std;

bool is_leap(int year){
	if((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)){
		return true;
	}else{
		return false;
	}
}

int main(){
	int m;
	cin>>m;
	string s;
	int year;
	int month;
	int day;
	int count;
	for(int i = 0; i < m; i++){
		cin>>s;
		year = (s[0] - 48) * 1000 + (s[1] - 48) * 100 + (s[2] - 48) * 10 + (s[3] - 48);
		month = (s[5] - 48) * 10 + (s[6] - 48);
		day = (s[8] - 48) * 10 + (s[9] - 48);
		if(is_leap(year) && month == 2 && day == 29){
			cout<<-1<<endl;
			continue;
		}
		count = 0;
		if(month <= 2){
			if(is_leap(year)){
				count++;
			}
		}
		year++;
		for(int j = 1; j <= 18; year++, j++){
			if(is_leap(year)){
				count++;
			}
		}
		year--;
		if(is_leap(year) && month <= 2){
			count--;
		}
		cout<<6570 + count<<endl;
	}
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值