为什么没通过呢

#include <iostream>
#include <string>
#include <vector>
#include <sstream>

using namespace std;




int month(const string &s)
{
	istringstream stream1(s);
	string mon;
	string days;
	int day;
	stream1>>mon>>days;
	istringstream stream2;
	stream2.str(days.substr(0,2));
	stream2>>day;

	if((mon=="January")||(mon=="February"&&day<29))
		return 0;   //smaller than 2.29
	else 
		if((mon=="February"&&day==29))
			return 1;  //equal than 2.29

		else 
			return 2;  //larger than 2.29
}


long lastFour(const string &s)
{
	auto it=s.end()-4;
	int  pos=it-s.begin();
	string ret=s.substr(pos,4);

	istringstream stream1;
	stream1.str(ret);
	long i;
	stream1>>i;
	return i;
}

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


int numLeapYear(const string &s1,const string &s2)
{
	long fromYear=lastFour(s1);
	long endYear=lastFour(s2);
	int sum=0;

	for(long i=fromYear;i<=endYear;i++)
	{
		if(isleapYear(i))
			sum++;
	}

	if(isleapYear(fromYear))
	{
		if(month(s1)==2)   //if day of fromyear larger than 2.29
			sum--;
	}
	if(isleapYear(endYear))
	{
		if(month(s2)==0) //if day of endyear smaller than 2.29
			sum--;
	}

	return sum;
}




int main()
{


	vector<string> years;
	int N;
	cin>>N;
	string year;
	cin.clear();

	getline(cin,year);
	while(getline(cin,year))
		years.push_back(year);

	//for(auto v:years)
	//	cout<<v<<endl;

    vector<int> results;
	int num;
	for(int i=0;i<N*2;i++)
	{
		num=numLeapYear(years[i],years[i+1]);
		results.push_back(num);
		i++;
	}

	for(int i=0;i<N;i++)
	{
		cout<<"Case #"<<i+1<<": "<<results[i]<<endl;
	}

	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值