zoukankan      html  css  js  c++  java
  • C++-蓝桥杯-日期问题[模拟题]

    翻日历即可,不需要想太复杂,第一次提交未考虑20世纪的答案了,87分,我服了

    以下是100分代码

     1 #include <set>
     2 #include <cstdio>
     3 #include <iostream>
     4 using namespace std;
     5 bool check(int year){return (year%4==0&&year%100!=0)||(year%400==0);}
     6 struct Date{
     7     int year,month,day;
     8     Date(int year=0,int month=0,int day=0):year(year),month(month),day(day){}
     9     void print(){
    10         printf("%d-",year);
    11         if(month<10)printf("0%d-",month);else printf("%d-",month);
    12         if(day<10)printf("0%d
    ",day);else printf("%d
    ",day);
    13     }
    14     void add(){
    15         day++;if(day<=28)return;
    16         if(day==29&&month==2&&!check(year))day=1,month++;
    17         else if(day==30&&month==2&&check(year))day=1,month++;
    18         else if(day==31&&(month==4||month==6||month==9||month==11))day=1,month++;
    19         else if(day==32&&(month==1||month==3||month==5||month==7||month==8||month==10))day=1,month++;
    20         else if(day==32&&month==12)day=1,month=1,year++;
    21     }
    22 };
    23 bool compile(Date A,Date B){return (A.day==B.day&&A.month==B.month&&A.year==B.year);}
    24 char s[15];
    25 int main(){
    26     scanf("%s",s+1);
    27     int a=(s[1]-'0')*10+(s[2]-'0');
    28     int b=(s[4]-'0')*10+(s[5]-'0');
    29     int c=(s[7]-'0')*10+(s[8]-'0');
    30     for(Date A=Date(1960,1,1),B=Date(2060,1,1);!compile(A,B);A.add())
    31         if(compile(Date(1900+a,b,c),A)||compile(Date(2000+a,b,c),A)|| //就是这里,我服了
    32            compile(Date(1900+c,a,b),A)||compile(Date(2000+c,a,b),A)|| //看到ABC<=9就把1900删了  
    33            compile(Date(1900+c,b,a),A)||compile(Date(2000+c,b,a),A)){ //我怕不是个是傻子
    34             A.print();
    35         }
    36     return 0;
    37 }
  • 相关阅读:
    老陌与博客
    有关模式窗体和无(非)模式窗体的区别
    10月9日至10月22日备忘录
    9月4日至9月10日备忘录
    VS2015 远程调试:Remote Debugger
    8月28日至9月3日备忘录
    8月21日至8月27日技术积累
    用函数方法实现迭代器
    python中eval, exec, execfile,和compile(转载)
    dev 中的GridControl中的行实现选择的功能实现
  • 原文地址:https://www.cnblogs.com/JasonCow/p/13746431.html
Copyright © 2011-2022 走看看