蓝桥杯java日期问题_蓝桥杯 日期问题 - osc_es0xbr6n的个人空间 - OSCHINA - 中文开源技术交流社区...

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

using namespace std;

const int MAXN = 100 + 10;

int a, b, c;

int m1[] = {31,28,31,30,31,30,31,31,30,31,30,31};

int m2[] = {31,29,31,30,31,30,31,31,30,31,30,31};

struct Node{

int y, m, d;

bool operator < (const Node&rhs)const{

return y < rhs.y || (y == rhs.y && m < rhs.m) || (y == rhs.y && m == rhs.m && d < rhs.d);

}

}num[10];

set st;

int cnt;

bool judge(int y){

if(y % 400 == 0) return true;

if(y % 100 != 0 && y % 4 == 0) return true;

return false;

}

bool judge1(){

if(a < 60){

num[cnt].y = 2000 + a;

}

else{

num[cnt].y = 1900 + a;

}

if(b < 1 || b > 12) return false;

if(judge(num[cnt].y)){

if(c >= 1 && c <= m2[b - 1]){

num[cnt].m = b;

num[cnt].d = c;

return true;

}

return false;

}

else{

if(c >= 1 && c <= m1[b - 1]){

num[cnt].m = b;

num[cnt].d = c;

return true;

}

return false;

}

}

bool judge2(){

if(c < 60){

num[cnt].y = 2000 + c;

}

else{

num[cnt].y = 1900 + c;

}

if(a < 1 || a > 12) return false;

if(judge(num[cnt].y)){

if(b >= 1 && b <= m2[a - 1]){

num[cnt].m = a;

num[cnt].d = b;

return true;

}

return false;

}

else{

if(b >= 1 && b <= m1[a - 1]){

num[cnt].m = a;

num[cnt].d = b;

return true;

}

return false;

}

}

bool judge3(){

if(c < 60){

num[cnt].y = 2000 + c;

}

else{

num[cnt].y = 1900 + c;

}

if(b < 1 || b > 12) return false;

if(judge(num[cnt].y)){

if(a >= 1 && a <= m2[b - 1]){

num[cnt].m = b;

num[cnt].d = a;

return true;

}

return false;

}

else{

if(a >= 1 && a <= m1[b - 1]){

num[cnt].m = b;

num[cnt].d = a;

return true;

}

return false;

}

}

int main(){

scanf("%d/%d/%d", &a, &b, &c);

cnt = 0;

if(judge1()){

++cnt;

}

if(judge2()){

++cnt;

}

if(judge3()){

++cnt;

}

sort(num, num + cnt);

for(int i = 0; i < cnt; ++i){

st.insert(num[i]);

}

for(set::iterator it = st.begin(); it != st.end(); ++it){

printf("%d-%02d-%02d\n", (*it).y, (*it).m, (*it).d);

}

return 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值