답안 #213236

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
213236 2020-03-25T10:46:39 Z Dremix10 Datum (COCI20_datum) C++17
35 / 50
38 ms 640 KB
#include <iostream>
using namespace std;

int d1,d2,m1,m2,y1,y2,y3,y4;
int d,m,y;
bool change=false;

void updateYear(){

    int temp=y;

    y4=temp%10;
    temp=temp/10;

    y3=temp%10;
    temp=temp/10;

    y2=temp%10;

    y1=temp/10;

    change=true;

}

void updateMonth(){

    m2=m%10;
    m1=m/10;

}

void updateDay(){

    d2=d%10;
    d1=d/10;

}

bool checkDays(){
//cout<<y3<<" "<<y4<<endl;
    if(y4>3){
        //change=true;

        y+=10-y4;
        updateYear();
        return 0;
    }

    if(y4==3){

        if(y3>1){
            //change=true;

            y+=10-y4;
            updateYear();
            return 0;
        }

        return 1;

    }

    if(y4==2 || y4==1){
   // cout<<"kalos"<<endl;
        return 1;

    }

    if(y3==0){
        //change=true;

        y++;
        updateYear();
        return 0;

    }

    return 1;

}

bool checkMonth(){
//cout<<y1<<" "<<y2<<endl;
    if(y2>1){
        //change=true;

        y+=1000-y2*100-y3*10-y4;
        updateYear();
        return 0;
    }

    if(y2==1){

        if(y1>2){

            y+=1000-y2*100-y3*10-y4;
            updateYear();
            return 0;
        }

        return 1;

    }

    if(y2==0){

        if(y1==0){

            y+=100-y3*10-y4;
            updateYear();
            return 0;
        }

        return 1;

    }


}


int main (){
int n;
cin>>n;

while(n--){
    string s;
    cin>>s;



    /// DD.MM.YYYY.

    d1=s[0]-'0';
    d2=s[1]-'0';

    m1=s[3]-'0';
    m2=s[4]-'0';

    y1=(int)(s[6]-'0');
    y2=s[7]-'0';
    y3=s[8]-'0';
    y4=s[9]-'0';

    int mg=m1*10+m2;
   // cout<<mg<<endl;
                    //int dg=y4*10+y3;
                        int allowed;
                        if(mg==1 || mg==3 || mg==5 || mg==7 || mg==8 || mg==10 || mg==12)
                        allowed=31;

                        else if(mg==4 || mg==6 || mg==9 || mg==11)
                        allowed=30;

                        else if(y%4==0)
                        allowed=29;

                        else
                        allowed=28;
//cout<<allowed<<endl;
    //d++;
m=m1*10+m2;
    d=d1*10+d2;
   // cout<<d<<" "<<m<<endl;
    d++;
    updateDay();
    y=y1*1000+y2*100+y3*10+y4;
//cout<<y<<endl;
    if(d>allowed){
        d=1;
        updateDay();
        m++;
        updateMonth();
        if(m>12){
            m=1;
            updateMonth();
            y++;
           // cout<<y<<endl;
            updateYear();
            //cout<<y<<endl;
        }
    }






    while(true){
//cout<<d<<" "<<m<<" "<<y<<endl;
        //cout<<checkDays()<<endl;
        if(checkDays() && checkMonth()){
          //  cout<<change<<endl;
            if(change){
                    int mg=y2*10+y1;
                    int dg=y4*10+y3;
                        int allowed;
                        if(mg==1 || mg==3 || mg==5 || mg==7 || mg==8 || mg==10 || mg==12)
                        allowed=31;

                        else if(mg==4 || mg==6 || mg==9 || mg==11)
                        allowed=30;

                        else if(y%4==0)
                        allowed=29;

                        else
                        allowed=28;


                if(dg<=allowed){
                d1=y4;
                d2=y3;
                m1=y2;
                m2=y1;
                break;
                }
                else{
                    y++;
                    updateYear();
                }
            }
            else{

                int mg=y2*10+y1;
                if(mg<m){
                    y++;
                    updateYear();
                }
                else{
                    int dg=y4*10+y3;


                    if(mg>m){
                        m1=y2;
                        m2=y1;

                        int allowed;
                        if(mg==1 || mg==3 || mg==5 || mg==7 || mg==8 || mg==10 || mg==12)
                        allowed=31;

                        else if(mg==4 || mg==6 || mg==9 || mg==11)
                        allowed=30;

                        else if(y%4==0)
                        allowed=29;

                        else
                        allowed=28;

                        if(dg<=allowed){
                        d1=y4;
                        d2=y3;
                        break;
                        }
                        else{
                            y++;
                            updateYear();
                        }

                    }
                    else{
                        m1=y2;
                        m2=y1;

                        int allowed;
                        if(mg==1 || mg==3 || mg==5 || mg==7 || mg==8 || mg==10 || mg==12)
                        allowed=31;

                        else if(mg==4 || mg==6 || mg==9 || mg==11)
                        allowed=30;

                        else if(y%4==0)
                        allowed=29;

                        else
                        allowed=28;

                        if(dg<d){
                            y++;
                            updateYear();
                        }
                        else{

                            if(dg<=allowed){
                                d1=y4;
                                d2=y3;
                                break;
                            }
                            else{
                                y++;
                                updateYear();
                            }


                        }
                    }


                }

            }


        }

    }
    cout<<d1<<d2<<"."<<m1<<m2<<"."<<y1<<y2<<y3<<y4<<"."<<endl;
}


}

Compilation message

datum.cpp: In function 'bool checkMonth()':
datum.cpp:120:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Incorrect 38 ms 640 KB Output isn't correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Incorrect 4 ms 256 KB Output isn't correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 256 KB Output is correct
10 Incorrect 38 ms 512 KB Output isn't correct