题解

129 条题解

  • 2
    @ 2017-09-19 09:59:38

    此题不存在BUG
    那些一开始想的百年不闰的,注意一下四百年再闰

    #include<iostream>
    int mo[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    using namespace std;
    int main()
    {
        int a,b,c,i;
        cin>>a>>b>>c;
        for(i=1;i<=10000;i++)
        {
            c++;
            if(a%4==0&&b==2)
            {
                if(c>29)
                {
                    c=1;
                    b++;
                }
            }
            else
             if(c>mo[b])
             {
                c=1;
                b++;
                if(b>12)
                 {
                    b=1;
                    a++;
                 }
             }
        }
        cout<<a<<"-"<<b<<"-"<<c;
        return 0;
    }
    
  • 1
    @ 2017-05-08 12:45:37
    /*
    水题直接乱搞不想多说
    */
    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    using namespace std;
    
    int y,m,d;
    int day[13];
    
    void init()
    {
        day[1]=31;  day[2]=28;  day[3]=31;  day[4]=30;
        day[5]=31;  day[6]=30;  day[7]=31;  day[8]=31;
        day[9]=30;  day[10]=31; day[11]=30; day[12]=31;
    }
    
    int main()
    {
        init();
        cin>>y>>m>>d;
        for (int i=1;i<=10000;i++)
        {
            if (y%4==0)
                day[2]=29;
            else day[2]=28;
                d++;
            if (d>day[m])
                m++,d=1;
            if (m==13)
                m=1,y++;
        }
        cout<<y<<"-"<<m<<"-"<<d<<endl;
        return 0;
    }
    
  • 0
    @ 2021-03-16 21:00:37
    #include <cmath>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <algorithm>
    #include <vector>
    #include <deque>
    using namespace std;
    
    namespace dts
    {
        int MT0[12]={31,28,31,30,31,30,31,31,30,31,30,31};
        #define MT0(x) MT0[(x)-1]
        int MT1[12]={31,29,31,30,31,30,31,31,30,31,30,31};
        #define MT1(x) MT1[(x)-1]
        class date{
        public:
            int Y,M,D;
            date nextday()
            {
                if (M==12&&D==MT0(12))
                {
                    date ans;
                    ans.Y=Y+1,ans.M=1,ans.D=1;
                    return ans;
                }
                if ((Y%4==0&&Y%100!=0)||Y%400==0)
                {
                    if (D==MT1(M))
                    {
                        date ans;
                        ans.Y=Y,ans.M=M+1,ans.D=1;
                        return ans;
                    }
                    else
                    {
                        date ans;
                        ans.Y=Y,ans.M=M,ans.D=D+1;
                        return ans;
                    }
                }
                else
                {
                    if (D==MT0(M))
                    {
                        date ans;
                        ans.Y=Y,ans.M=M+1,ans.D=1;
                        return ans;
                    }
                    else
                    {
                        date ans;
                        ans.Y=Y,ans.M=M,ans.D=D+1;
                        return ans;
                    }
                }
            }
        };
        
        date btd,ans;
        
        void main()
        {
            scanf("%d%d%d",&btd.Y,&btd.M,&btd.D);
            ans=btd;
            for (int i=1;i<=10000;i++)
                ans=ans.nextday();
            printf("%d-%d-%d\n",ans.Y,ans.M,ans.D);
        }
    };
    
    int main()
    {
        dts::main();
    }
    
  • 0
    @ 2018-04-18 09:26:04

    #include <iostream>
    #include <cstdio>

    using namespace std;

    int y,m,d;
    int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

    int main()
    {

    cin>>y>>m>>d;
    for (int i=1;i<=10000;i++)
    {
    if (y%4==0)
    day[2]=29;
    else day[2]=28;
    d++;
    if (d>day[m])
    m++,d=1;
    if (m==13)
    m=1,y++;
    }
    cout<<y<<"-"<<m<<"-"<<d<<endl;
    return 0;
    }

  • 0
    @ 2018-03-20 13:33:43

    #include<iostream>
    #include<cmath>
    using namespace std;
    int m[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    int main()
    {
    int a,b,c;
    cin>>a>>b>>c;
    for (int i=1;i<=10000;i++)
    {
    c++;
    if ((a%4==0&&a%100!=0)||a%400==0)
    {
    m[2]=29;
    if (m[b]<c)
    {
    b++;
    c=1;
    if (b==13)
    {
    a++;
    b=1;
    }
    }
    m[2]=28;
    }
    else
    {
    if (m[b]<c)
    {
    b++;
    c=1;
    if (b==13)
    {
    a++;
    b=1;
    }
    }
    }
    }
    cout<<a<<"-"<<b<<"-"<<c;
    return 0;
    }

  • 0
    @ 2018-02-02 10:42:37

    八年以后再来看,用 Python 多简单。

    import datetime

    data = list(map(int, input().strip().split(' ')))
    date = datetime.date(year=data[0], month=data[1], day=data[2])
    date += datetime.timedelta(days=10000)
    print(date.strftime('%Y-%-m-%-d'))

  • 0
    @ 2017-08-19 13:53:17

    program huiwen;

    var
    month, ans, a, b, y, code, d, q, w, e: longint;
    str1, str2, stry, strm, strd, year, s, s1, s2: string;

    begin
    readln(q, w, e);
    ans := 0;
    str(q, stry);
    str(w, strm);
    if length(strm) = 1 then
    begin
    strm := '0' + strm[1];
    end;
    str(e, strd);
    if length(strd) = 1 then
    begin
    strd := '0' + strd[1];
    end;
    y := 0;
    val(stry, y, code);

    repeat
    if (strm = '01') or (strm = '03') or (strm = '05') or (strm = '07') or
    (strm = '08') or (strm = '10') or (strm = '12') then
    month := 31
    else if strm <> '02' then
    month := 30
    else
    begin

    if ((y mod 4 = 0) and (y mod 100 <> 0)) or (y mod 400 = 0) then
    month := 29
    else
    month := 28;
    end;
    if strd[1] = '0' then
    begin
    s := copy(strd, 2, 1);
    val(s, d, code);
    end
    else
    val(strd, d, code);
    if (strm = '12') and (d = month) then
    begin
    Inc(y);
    strm := '01';
    strd := '01';
    str(y, stry);
    d := 0;
    end
    else
    if (strm = '09') and (d = month) then
    begin
    strm := '10';
    strd := '01';
    d := 0;
    end
    else
    if (d = month) then
    begin
    strm[2] := chr(Ord(strm[2]) + 1);
    strd := '01';
    d := 0;
    end
    else
    begin
    Inc(d);
    str(d, strd);
    if length(strd) = 1 then
    strd := '0' + strd;
    end;
    Inc(ans);
    until ans = 10000;
    if strm[1] = '0' then
    s1 := copy(strm, 2, 1)
    else
    s1 := strm;
    if strd[1] = '0' then
    s2 := copy(strd, 2, 1)
    else
    s2 := strd;
    writeln(stry, '-', s1, '-', s2);
    end.

  • 0
    @ 2017-05-25 17:40:53

    #include<iostream>
    #include<cstdio>
    using namespace std;
    int main()
    {
    int n,y,r,rr,d=10000;
    cin>>n>>y>>r;
    for(d=10000;d>0;d--)
    {r++;
    if(n%4!=0)
    {switch(y)
    {case 2:rr=28;break;
    case 4:rr=30;break;
    case 6:rr=30;break;
    case 9:rr=30;break;
    case 11:rr=30;break;
    default:rr=31;break;
    }
    if(r>rr){y++;r=1;}
    if(y>12){n++;y=1;}}
    else{switch(y)
    {case 2:rr=29;break;
    case 4:rr=30;break;
    case 6:rr=30;break;
    case 9:rr=30;break;
    case 11:rr=30;break;
    default:rr=31;break;
    }
    if(r>rr){y++;r=1;}
    if(y>12){n++;y=1;}}
    }
    cout<<n<<"-"<<y<<"-"<<r;
    return 0;
    }

  • 0
    @ 2017-01-07 14:43:28
    
    int pd(int x) {
        if (x % 4 == 0) {
            if (x % 100 != 0 || x % 400 == 0) return 1;
        }
        return 0;
    }
    
    int main () {
        int i, dtot = 0, y, m, d, dd, k, day[2][13] = {{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}}, yd[2] = {365, 366};
        scanf("%d%d%d", &y, &m, &d);
        k = pd(y);
        for (i = 1; i < m; i++) dtot += day[k][i];
        dtot += d - 1;
        dd = 10000;
        m = 1;
        d = 1;
        while (dd >= yd[k]) {
            dd -= yd[k];
            k = pd(++y);
        }
        while (dd >= day[k][m]) {
            dd -= day[k][m];
            m++;
        }
        d += dd;
        while (dtot >= day[k][m]) {
            dtot -= day[k][m];
            m++;
            if (m > 12) {
                y++;
                m = 1;
                k = pd(y);
            }
        }
        while (dtot) {
            d++;
            dtot--;
            if (d > day[k][m]) {
                m++;
                d = 1;
            }
            if (m > 12) {
                y++;
                m = 1;
                k = pd(y);
            }
        }
        printf("%d-%d-%d", y, m, d);
        return 0;
    }```
    
  • 0
    @ 2016-12-21 20:13:21

    哈哈哈哈哈 纯模拟你敢信吗,供参考,代码逻辑清晰的一逼
    ```c++
    #include<cstdio>
    #include<cmath>
    #include<cstring>
    int main()
    {
    int year,month,day;
    int sh[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
    int th[13] = {0,31,29,31,30,31,30,31,31,30,31,30,31};
    scanf("%d%d%d",&year,&month,&day);
    for(int i=1; i <= 10000; i++,day++)
    {
    // printf("month = %d day = %d\n",month,day);
    //是闰年
    if(year % 400==0||(year % 4 == 0 && year % 100 != 0))
    {

    if(day+1 > th[month])
    {
    if(month == 12)
    {
    year++;
    month = 0;
    }
    month++;
    day = 0;
    }

    }
    else
    {
    if(day+1 > sh[month])
    {
    if(month == 12)
    {
    year++;
    month = 0;
    }
    month++;
    day = 0;
    }
    }
    }
    printf("%d-%d-%d\n",year,month,day);

    return 0;
    }

  • 0
    @ 2016-06-16 19:37:55

    /*注意到数据不大,直接枚举*/
    #include <cstdio>
    #define Limit 10000
    #define MonthCou 12

    int MonDay[MonthCou] = {31,28,31,30,31,30,31,31,30,31,30,31};

    int year,month,day;

    bool IsR(){
    if((year%4 == 0&&year%100 != 0)||(year%100 == 0&&year%400 == 0)) return true;
    else return false;
    }

    void increase(){
    if(IsR()) MonDay[1] = 29; //判断闰年
    else MonDay[1] = 28; //千万不要忘记复位!
    day++;
    if(day > MonDay[month-1]){ day = 1; month++; }

    //一定要注意月份和天数是从 1 开始的,资深 OIer 可能会写成 0 ,就像我 ......
    if(month > MonthCou){ month = 1; year++; }
    }

    int main(){
    scanf("%d %d %d",&year,&month,&day);
    for(int i = 1; i <= Limit; i++) increase();
    printf("%d-%d-%d\n",year,month,day);

    return 0;
    }

  • 0
    @ 2016-05-25 13:42:45

    var
    q:array[1..12] of integer;
    a,i,o,p:integer;
    begin
    read(a,o,p);
    q[1]:=31;
    q[3]:=31;
    q[4]:=30;
    q[5]:=31;
    q[6]:=30;
    q[7]:=31;
    q[8]:=31;
    q[9]:=30;
    q[10]:=31;
    q[11]:=30;
    q[12]:=31;
    for i:=1 to 10000 do
    begin
    inc(p);
    if p >q[o] then begin
    inc(o);
    p:=1;
    if o>12 then begin
    inc(a);
    o:=1;
    end;
    if (a mod 4=0) and (a mod 100<>0) or (a mod 400=0) then q[2]:=29
    else q[2]:=28;
    end;

    end;
    write(a,'-',o,'-',p);
    end.

  • 0
    @ 2016-03-08 20:05:21

    var
    yf:array[1..12]of integer;
    i,j,k,y,m,d,ay,am,ad:longword;
    begin
    readln(y,m,d);
    yf[1]:=31; yf[3]:=31; yf[4]:=30; yf[5]:=31; yf[6]:=30;
    yf[7]:=31; yf[8]:=31; yf[9]:=30; yf[10]:=31; yf[11]:=30; yf[12]:=31;
    for i:=1 to 10000 do
    begin
    inc(d);
    if d>yf[m] then
    begin
    inc(m);
    d:=1;
    end;
    if m>12 then
    begin
    inc(y);
    m:=1;
    end;
    if (y mod 4=0)and(y mod 100<>0)or(y mod 400=0) then
    yf[2]:=29 else yf[2]:=28;
    end;
    writeln(y,'-',m,'-',d);
    end.

  • 0
    @ 2016-02-12 20:47:12

    我去坑爹啊,测试数据不用补0,害我20分还以为什么
    Pascal AC
    var n,y,m,d,i,k:longint;
    a:array[1..12]of longint=(31,28,31,30,31,30,31,31,30,31,30,31);
    begin
    read(y,m,d);
    n:=10000;
    if (y mod 4=0)and(y mod 100<>0)or(y mod 400=0) then a[2]:=29;
    for i:=1 to m-1 do
    n:=n+a[i];
    m:=1;
    n:=n+d-1;
    d:=1;
    while n>364 do
    begin
    if (y mod 4=0)and(y mod 100<>0)or(y mod 400=0) then
    begin
    if n-366>=0 then begin
    n:=n-366;
    inc(y);
    end
    else break;
    end
    else begin
    n:=n-365;
    inc(y);
    end;
    end;
    a[2]:=28;
    if (y mod 4=0)and(y mod 100<>0)or(y mod 400=0) then a[2]:=29;
    for i:=1 to 12 do
    if n-a[i]>=0 then
    begin
    n:=n-a[i];
    inc(m);
    end;
    d:=d+n;
    write(y,'-',m,'-',d);
    end.

  • 0
    @ 2016-02-01 10:09:04

    本来,闰年是一个很复杂的东西,但是由于这题的year可以被控制在1949<=year<=2099,所以,没必要考虑别的,直接用year对4取模,结果是0就是闰年,否则就不是
    #include<iostream>
    using namespace std;
    int main()
    {
    int y,m,d,day[13];
    cin>>y>>m>>d;
    day[1]=31;
    day[2]=28;
    day[3]=31;
    day[4]=30;
    day[5]=31;
    day[6]=30;
    day[7]=31;
    day[8]=31;
    day[9]=30;
    day[10]=31;
    day[11]=30;
    day[12]=31;
    for (int i=1;i<=10000;i++)
    {
    if (y%4==0)
    day[2]=29;
    else day[2]=28;
    d++;
    if (d>day[m])
    {
    m++;
    d=1;
    }
    if (m==13)
    {
    m=1;
    y++;
    }
    }
    cout<<y<<"-"<<m<<"-"<<d;
    }

  • 0
    @ 2016-01-01 00:42:21

    献上我的愚见:program p1211;
    var
    y,m,d:longint;
    yuefen:array[1..12] of longint;
    i,x:longint;
    begin
    readln(y,m,d);
    yuefen[1]:=31;
    yuefen[10]:=31;yuefen[11]:=30;yuefen[12]:=31;
    yuefen[3]:=31;yuefen[4]:=30;yuefen[5]:=31;yuefen[6]:=30;yuefen[7]:=31;yuefen[8]:=31;yuefen[9]:=30;
    for i:=1 to 10000 do
    begin
    inc(d);
    if d>yuefen[m] then
    begin
    inc(m);d:=1;
    end;
    if m>12then
    begin
    inc(y);
    m:=1;
    d:=1;
    end;
    if ((y mod 100 =0) and (y mod 400 =0)) or ((y mod 100 <>0 ) and (y mod 4=0)) then
    yuefen[2]:=29 else yuefen[2]:=28;
    end;
    writeln(y,'-',m,'-',d);

    readln;readln;
    end.

  • 0
    @ 2015-12-26 16:15:35

    第一百题纪念!
    #include <cstdio>
    #include <cstdlib>

    using namespace std;

    int y, m, d;
    int main(int argc, const char *argv[]) {
    scanf("%d %d %d", &y, &m, &d);
    for (int i = 1; i <= 10000; ++i) {
    ++d;
    if (d == 29 && m == 2 && y % 4 != 0) {
    m = 3;
    d = 1;
    continue;
    }
    if (d == 30 && m == 2 && ((y % 4 == 0 && y % 100 != 0) || (y % 400 == 0))) {
    m = 3;
    d = 1;
    continue;
    }
    if (d == 31 && (m == 4 || m == 6 || m == 9 || m == 11)) {
    ++m;
    d = 1;
    }
    if (d == 32 && (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12)) {
    ++m;
    d = 1;
    }
    if (m == 13) {
    ++y;
    m = 1;
    d = 1;
    }
    }
    printf("%d-%d-%d\n", y, m, d);
    return 0;
    }

  • 0
    @ 2015-11-20 19:52:07

    #include<stdio.h>
    int ping[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    int yun[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
    int f(int x)
    {
    if(x%400==0||((x%100!=0)&&(x%4==0)))
    {
    return 366;
    }
    else
    {
    return 365;
    }
    }
    bool f1(int x)
    {
    if(x%400==0||((x%100!=0)&&(x%4==0)))
    {
    return 1;
    }
    else
    {
    return 0;
    }
    }
    int main()
    {int nian,yue,ri;
    while(scanf("%d%d%d",&nian,&yue,&ri)!=EOF)
    {
    int i,j;
    int n1;
    n1=10000;
    while(n1-f(nian)>=0)
    {
    nian++;
    n1-=f(nian);
    }
    if(f1(nian))
    {
    n1-=(yun[yue]-ri);
    n1--;
    ri=1;
    yue++;
    int dd;
    dd=0;
    for(i=yue;i<=12;i++)
    {
    if(n1-yun[i]<0)
    {
    dd=1;//˵Ã÷ûÓнüλ
    break;
    }
    else
    {
    n1-=yun[i];
    yue++;
    }
    }
    if(dd==1)
    {
    printf("%d-%d-%d",nian,yue,ri+n1);
    }
    else
    {
    nian++;
    yue=1;
    for(i=yue;i<=12;i++)
    {
    if(n1-ping[i]<0)
    {
    break;
    }
    else
    {
    n1-=ping[i];
    yue++;
    }
    }

    printf("%d-%d-%d",nian,yue,ri+n1);
    }
    }
    else
    {
    n1-=(ping[yue]-ri);
    n1--;
    ri=1;
    yue++;
    int dd;
    dd=0;
    for(i=yue;i<=12;i++)
    {
    if(n1-ping[i]<0)
    {
    dd=1;//˵Ã÷ûÓнüλ
    break;
    }
    else
    {
    n1-=ping[i];
    yue++;
    }
    }
    if(dd==1)
    {
    printf("%d-%d-%d",nian,yue,ri+n1);
    }
    else
    {
    nian++;
    if(f1(nian))
    {
    yue=1;
    for(i=yue;i<=12;i++)
    {
    if(n1-yun[i]<0)
    {
    break;
    }
    else
    {
    n1-=yun[i];
    yue++;
    }
    }

    printf("%d-%d-%d",nian,yue,ri+n1);
    }
    else
    {
    yue=1;
    for(i=yue;i<=12;i++)
    {
    if(n1-ping[i]<0)
    {
    break;
    }
    else
    {
    n1-=ping[i];
    yue++;
    }
    }

    printf("%d-%d-%d",nian,yue,ri+n1);
    }
    }
    }
    }
    return 0;
    }

  • 0
    @ 2015-01-09 19:59:11

    哦= =要当心不要一到30天就换月,因为30号你还没过= =555,磨蹭了我好久。
    ###block code
    program P1211;
    var y,m,d,i:longint;
    pd:boolean;
    function runnian(x:longint):boolean;
    begin
    if ((x mod 4=0) and (x mod 100<>0)) or (x mod 400=0) then
    exit(true)
    else
    exit(false);
    end;

    procedure change;
    begin
    case m of
    1:if d=32 then begin d:=1; inc(m); end;
    3:if d=32 then begin d:=1; inc(m); end;
    4:if d=31 then begin d:=1; inc(m); end;
    5:if d=32 then begin d:=1; inc(m); end;
    6:if d=31 then begin d:=1; inc(m); end;
    7:if d=32 then begin d:=1; inc(m); end;
    8:if d=32 then begin d:=1; inc(m); end;
    9:if d=31 then begin d:=1; inc(m); end;
    10:if d=32 then begin d:=1; inc(m); end;
    11:if d=31 then begin d:=1; inc(m); end;
    12:if d=32 then begin d:=1; inc(m); end;
    end;

    pd:=runnian(y);

    if m=2 then
    begin
    if (pd=true) and (d=30) then
    begin
    d:=1; inc(m);
    end;
    if (pd=false) and (d=29) then
    begin
    d:=1; inc(m);
    end;
    end;

    if m=13 then
    begin
    inc(y); m:=1;
    end;

    end;

    begin //main
    read(y,m,d);
    for i:=1 to 10000 do
    begin
    inc(d);
    if (d>=28) and (m=2) then
    change;
    if d>=30 then
    change;
    end;

    write(y,'-',m,'-',d);
    end.

  • 0
    @ 2014-10-19 15:13:11

    过了!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

信息

ID
1211
难度
3
分类
模拟 点击显示
标签
(无)
递交数
2740
已通过
1333
通过率
49%
被复制
16
上传者