답안 #241987

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
241987 2020-06-26T13:20:35 Z stev2005 Datum (COCI20_datum) C++17
35 / 50
36 ms 532 KB
#include<iostream>
#include<string>
using namespace std;
struct date
{
    int day,month,year;
    date(){}
    date(int _day,int _month,int _year)
    {day=_day;month=_month;year=_year;}
    void init_year()
    {
        year=0;
        year=year*10+(month%10);
        year=year*10+(month/10%10);
        year=year*10+(day%10);
        year=year*10+(day/10%10);
    }
    void init_ans(string &s)
    {
        char c;int t='0';
        c=(char)((day/10%10)+t);
        s+=c;
        c=(char)((day%10)+t);
        s+=c;
        s+='.';
        c=(char)(month/10%10+t);
        s+=c;
        c=(char)(month%10+t);
        s+=c;
        s+='.';
        c=(char)(year/1000%10+t);
        s+=c;
        c=(char)(year/100%10+t);
        s+=c;
        c=(char)(year/10%10+t);
        s+=c;
        c=(char)(year%10+t);
        s+=c;
        s+='.';
    }
};
const int inf=(1<<20);
string in,ans;
int cury;
void init_in()
{
    cury=0;
    int t='0';
    cury=cury*10+((int)in[6]-t);
    cury=cury*10+((int)in[7]-t);
    cury=cury*10+((int)in[8]-t);
    cury=cury*10+((int)in[9]-t);
}
void solve()
{
    int raz=inf;
    date curans;
    for(int month=1;month<=12;month++)
    {
        if(month==2)
        {
            for(int day=1;day<=29;day++)
            {
                date cur(day,month,0);
                cur.init_year();
                ///cout<<cur.day<<' '<<cur.month<<' '<<cur.year<<endl;
                if(cur.year-cury<raz&&cur.year-cury>=0)
                {
                    raz=cur.year-cury;
                    curans=cur;
                    ///cout<<curans.day<<' '<<curans.month<<' '<<curans.year<<endl;
                }
            }
        }
        if(month==4||month==6||month==9||month==11)
        {
            for(int day=1;day<=30;day++)
            {
                date cur(day,month,0);
                cur.init_year();
                ///cout<<cur.day<<' '<<cur.month<<' '<<cur.year<<endl;
                if(cur.year-cury<raz&&cur.year-cury>=0)
                {
                    raz=cur.year-cury;
                    curans=cur;
                    ///cout<<curans.day<<' '<<curans.month<<' '<<curans.year<<endl;
                }
            }
        }
        else
        {
            for(int day=1;day<=31;day++)
            {
                date cur(day,month,0);
                cur.init_year();
                ///cout<<cur.day<<' '<<cur.month<<' '<<cur.year<<endl;
                if(cur.year-cury<raz&&cur.year-cury>=0)
                {
                    raz=cur.year-cury;
                    curans=cur;
                    ///cout<<curans.day<<' '<<curans.month<<' '<<curans.year<<endl;
                }
            }
        }
    }
    ans="";
    curans.init_ans(ans);
    ///cout<<curans.day<<' '<<curans.month<<' '<<curans.year<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>in;
        init_in();
        solve();
        cout<<ans<<endl;
    }
return 0;
}

Compilation message

datum.cpp: In function 'void solve()':
datum.cpp:31:22: warning: '*((void*)& curans +8)' may be used uninitialized in this function [-Wmaybe-uninitialized]
         c=(char)(year/1000%10+t);
                  ~~~~^~~~~
datum.cpp:57:10: note: '*((void*)& curans +8)' was declared here
     date curans;
          ^~~~~~
datum.cpp:26:23: warning: '*((void*)& curans +4)' may be used uninitialized in this function [-Wmaybe-uninitialized]
         c=(char)(month/10%10+t);
                  ~~~~~^~~
datum.cpp:57:10: note: '*((void*)& curans +4)' was declared here
     date curans;
          ^~~~~~
datum.cpp:21:22: warning: 'curans' may be used uninitialized in this function [-Wmaybe-uninitialized]
         c=(char)((day/10%10)+t);
                   ~~~^~~
datum.cpp:57:10: note: 'curans' was declared here
     date curans;
          ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 36 ms 532 KB Output isn't correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Incorrect 4 ms 384 KB Output isn't correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Incorrect 33 ms 504 KB Output isn't correct