
第一行输入一个整数,表示可挑选的日期,第二行输入N个日期,每个日期的格式为年月,求输出最长的施工期的月份数量,先求出最小的日期和最大的日期再计算它们的月份之差。

输入不给你考虑
#include<iostream>
#include<cstring>
#include <vector>
#include <stdio.h>
#include <algorithm>
using namespace std;
struct Date {
int year;
int month;
Date(int y=2000,int m=1):year(y),month(m){}
bool operator<(const Date& rh) {
if(year<rh.year)
return true;
else if (year == rh.year) {
return month<rh.month;
}
else {
return false;
}
}
int operator-(const Date& rh){
Date t1=*this;
Date t2=rh;
int flag=1;
if(t1<t2){
swap(t1,t2);
flag=-1;
}
int dify=t1.year-t2.year;
if(dify>1)
dify=(dify-1)*12;
else
dify=0;
int difm1=12-t2.month;
int difm2=t1.month;
return flag*(dify+difm1+difm2);
}
};
int main()
{
vector<Date> vec{{2019,6},{2018,7},{2020,12}};
sort(vec.begin(),vec.end());
int ans=*(vec.end()-1)-*vec.begin();
cout<<ans;
}