#include<iostream>
#include<string>
using namespace std;
int day1[13] = { 0,31,29,31,30,31,30,31,31,30,31,30,31 };
int day2[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
/*
解题思路:
1.按回文规则得到新数组
2.判断得到新数组日期是否合法
2.1第一次需判断是否在原日期之后
3.年份+1
4.重复第1-3步
5.输出正确答案
回文日期第一行
ABABBABA型日期
1.按格式规则得到新数组
2.判断是否合法
3.前两位增加
4.重复前三步
*/
class Date
{
private:
int d[8];
public:
Date()
{
memset(d, 0, 8);
}
Date(string& s)
{
for (int i = 0; i < 8; i++)
{
d[i] = s[i] - '0';
}
}
int Gety()
{
int year;
return year = 1000 * d[0] + 100 * d[1] + 10 * d[2] + d[3];
}
int Getm()
{
int month;
return month = 10 * d[4] + d[5];
}
int Getd()
{
int day;
return day = 10 * d[6] + d[7];
}
//d[0]-d[3]->year
//d[4]-d[5]->month
//d[6]-d[7]->day
bool IsLeapYear(int year)
{
if (year % 400 == 0 || year % 4 == 0 && year % 400 != 0)
return true;
else
return false;
}
bool Judge()
{
if (IsLeapYear(Gety()))
{
if (Getd() <= day1[Getm()])
{
return true;
}
else
return false;
}
else
{
if (Getd() <= day2[Getm()])
{
return true;
}
else
return false;
}
}
bool JudgePrior(int* d)
{
int mon = 10 * d[4] + d[5];
int day = 10 * d[6] + d[7];
if (Getm() > mon)
return true;
else if (Getm() == mon && Getd() > day)
return true;
else
return false;
}
void Yearzj()
{
d[3]++;
int i = 3;
do
{
d[i - 1] += d[i] / 10;
d[i] = d[i] % 10;
} while (--i>0);
}
void Create()
{
for (int i = 4; i < 8; i++)
{
d[i] = d[7 - i];
}
}
void Zj()
{
d[1]++;
d[0] += d[1] / 10;
d[1] %= 10;
}
//ABABBABA
void Create2()
{
d[7] = d[5] = d[2] = d[0];
d[6] = d[4] = d[3] = d[1];
}
void Next()
{
int original[8];
bool first = true;
for (int i = 0; i < 8; i++)
{
original[i] = d[i];
}
while (true)
{
int i = 0;
this->Yearzj();
this->Create();
if (first)
{
first = false;
if (this->JudgePrior(original) && this->Judge())
break;
}
else if (this->Judge())
break;
else
continue;
}
this->Print();
//输出下一个回文日期
for (int i = 0; i < 8; i++)
{
d[i] = original[i];
}
while (true)
{
this->Zj();
this->Create2();
if (this->Judge())
break;
else
continue;
}
this->Print();
//ABABBABA
}
void Print()
{
for (int i = 0; i < 8; i++)
cout << d[i];
cout << endl;
}
};
int main()
{
string s;
cin >> s;
Date D(s);
D.Next();
system("pause");
return 0;
}