这种日期模拟题是怎么也做不对的。
卡了N发才卡完所有test case
要考虑到日期合法,去重,排序输出
#include<cstdio>
#include<algorithm>
struct Da{
int y, m, d;
bool operator < (const Da &A) const
{
if(y == A.y){
if(m == A.m) return d < A.d;
return m < A.m;
}
return y < A.y;
}
bool operator != (const Da &A) const
{
if(y != A.y || m != A.m || d != A.d) return true;
return false;
}
}D[3];
bool judge(int y, int m, int d){
if(m == 0 || d == 0) return false;
if(m > 12) return false;
if(m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12)
if(d > 31) return false;
if(m == 4 || m == 6 || m == 9 || m == 11)
if(d > 30) return false;
if(m == 2){
y += 1900;
if(y % 100 < 60) y += 100;
if((y % 4 == 0 && y % 100 != 0) || y % 400 == 0){
if(d > 29) return false;
}
else {
if(d > 28) return false;
}
}
return true;
}
int main()
{
int a, b, c, g = 0;
scanf("%d/%d/%d", &a, &b, &c);
//1.年月日abc
if(judge(a, b, c)){
D[g].y = 1900 + a; D[g].m = b; D[g].d = c;
if(a < 60) D[g].y += 100;
g++;
}
//2.月日年abc
if(judge(c, a, b)){
D[g].y = 1900 + c; D[g].m = a; D[g].d = b;
if(c < 60) D[g].y += 100;
g++;
}
//3.日月年abc
if(judge(c, b, a)){
D[g].y = 1900 + c; D[g].m = b; D[g].d = a;
if(c < 60) D[g].y += 100;
g++;
}
std::sort(D, D + g);
printf("%d-%02d-%02d\n", D[0].y, D[0].m, D[0].d);
for(int i = 1; i < g; i++)
if(D[i] != D[i - 1]) printf("%d-%02d-%02d\n", D[i].y, D[i].m, D[i].d);
return 0;
}