Submission #241987

#TimeUsernameProblemLanguageResultExecution timeMemory
241987stev2005Datum (COCI20_datum)C++17
35 / 50
36 ms532 KiB
#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 (stderr)

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;
          ^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...