zoukankan      html  css  js  c++  java
  • 日期问题

    OJ链接:http://lx.lanqiao.cn/problem.page?gpid=T443

    模拟题,但是我走入了误区,导致开始出错。

    代码:

    #include <stdio.h>
    #include <memory.h>
    #include <math.h>
    #include <string>
    #include <string.h>
    #include <vector>
    #include <set>
    #include <stack>
    #include <queue>
    #include <algorithm>
    #include <map>
    
    
    #define I scanf
    #define OL puts
    #define O printf
    #define F(a,b,c) for(a=b;a<c;a++)
    #define FF(a,b) for(a=0;a<b;a++)
    #define FG(a,b) for(a=b-1;a>=0;a--)
    #define LEN 3000
    #define MAX 0x06FFFFFF
    #define V vector<int>
    
    using namespace std;
    
    typedef struct Date{
        int y,m,d;
        Date(int y=0,int m=0,int d=0):y(y),m(m),d(d){
        }
        bool operator <(const Date& o) const
        {
            if(y<o.y) return true;
            if(y==o.y && m<o.m) return true;
            if(y==o.y && m==o.m && d<o.d) return true;
            return false;        
        }
    }Date;
    
    
    set<Date> dt;
    
    void add_date(int y,int m,int d){
        if(y<1960 || y>2059) return;
        if(m<=0 || m>12) return;
        if(d<=0) return;
        bool isRN=false;
        if(y%400==0 || (y%100!=0 && y%4==0) ){
            isRN=true;
        }
        if(m==1 ||m==3 ||m==5 ||m==7 ||m==8 ||m==10 ||m==12){
            if(d>31) return;
        }else if(m==2){
            if(isRN){
                if(d>29) return;
            }else{
                if(d>28) return;
            }
        }else{
            if(d>30) return;
        }
        dt.insert(Date(y,m,d));
    }
    
    int main(){
    //    freopen("D:/CbWorkspace/blue_bridge/日期问题.txt","r",stdin);
        int a,b,c;
        I("%d/%d/%d",&a,&b,&c); 
        add_date(1900+a,b,c);
        add_date(1900+c,a,b);
        add_date(1900+c,b,a);
        add_date(2000+a,b,c);
        add_date(2000+c,a,b);
        add_date(2000+c,b,a);
        set<Date>::iterator it=dt.begin();
        while(it!=dt.end()){
            printf("%04d-%02d-%02d
    ",it->y,it->m,it->d);
            it++;
        }
        return 0;
    }
  • 相关阅读:
    求解:块级元素的宽度自适应问题
    list 小练习
    codevs1017乘积最大
    codevs1048石子归并
    luogu1387 最大正方形
    BZOJ1305: [CQOI2009]dance跳舞
    linux下分卷tar.bz文件的合并并解压缩
    ubuntu命令查补
    认识与学习BASH(中)
    认识与学习BASH
  • 原文地址:https://www.cnblogs.com/TQCAI/p/8455299.html
Copyright © 2011-2022 走看看