由于审核时,大段题目 文字和其他文章题目内容 重复,导致审核不过,所以这里题目略:
AC代码:
#include <iostream>
#include <string.h>
#include <sstream>
#include <vector>
#include <algorithm>
using namespace std;
string date;
string AA,BB,CC;
int aa,bb,cc;
vector<string> Dates;
int StoI(string st){
stringstream ss(st);
int t;
ss>>t;
return t;
}
string ItoS(int t){
stringstream is;
is<<t;
return is.str();
}
void getAABBCC(){
AA=date.substr(0,2);//从下标2开始的2个子串
BB=date.substr(3,2);
CC=date.substr(6,2);
aa=StoI(AA);
bb=StoI(BB);
cc=StoI(CC);
}
/*
这些日期都在1960年1月1日至2059年12月31日
*/
int leap[12]={31,29,31,30,31,30,31,31,30,31,30,31};//闰年
int common[12]={31,28,31,30,31,30,31,31,30,31,30,31};//平年
bool isLeap(int year){
if( (year%4==0 && year%100!=0) || year%400==0 )
return true;
return false;
}
void getExactDate(int year,int month,int day){
string res="error";
if( (isLeap(year) && day<=leap[month-1]) ||
(!isLeap(year) && day<=common[month-1]) )
res=ItoS(year)+"-"+((month<10)?("0"):(""))+ItoS(month)+"-"+
((day<10)?("0"):(""))+ItoS(day);
if(res!="error" && find(Dates.begin(),Dates.end(),res)==Dates.end() )//日期正确且未重复
Dates.push_back(res);
}
void isYYMMDD(){
if(BB>"00" && BB<="12" && CC>"00" && CC<="31"){
int year;
if(AA<="59")
year=StoI("20"+AA);
else
year=StoI("19"+AA);
getExactDate(year,bb,cc);
}
}
//AA BB CC
void isMMDDYY(){
if(AA>"00" && BB>"00" && AA<="12" && BB<="31"){
int year;
if(CC<="59")
year=StoI("20"+CC);
else
year=StoI("19"+CC);
getExactDate(year,aa,bb);
}
}
// AA BB CC
void isDDMMYY(){
if(BB>"00" && AA>"00" && BB<="12" && AA<="31"){
int year;
if(CC<="59")
year=StoI("20"+CC);
else
year=StoI("19"+CC);
getExactDate(year,bb,aa);
}
}
int main()
{
cin>>date;
getAABBCC();
isYYMMDD();
isMMDDYY();
isDDMMYY();
sort(Dates.begin(),Dates.end());
for(int i=0;i<Dates.size();i++)
cout<<Dates[i]<<endl;
return 0;
}