Submission #237630

#TimeUsernameProblemLanguageResultExecution timeMemory
237630akatDatum (COCI20_datum)C++14
50 / 50
18 ms512 KiB
#include<bits/stdc++.h> using namespace std; int get(string &s,int i,int n) { int ans = 0; for(;i<n;i++) ans = ans * 10 + s[i] - '0'; return ans; } int rev(int x) { return (x % 10) * 10 + x / 10; } const int MONTHS = 12; int month_len[MONTHS+1] = {-1,31,29,31,30,31,30,31,31,30,31,30,31}; void print(int x,int len) { int y = x; while(y) { y /= 10; len--; } while(len--) cout<<0; cout<<x<<'.'; } void solve() { string s; cin>>s; int day = get(s,0,2); int month = get(s,3,5); int year = get(s,6,10); int palmonth = (year % 1000) / 100 * 10 + year / 1000; int palday = (year % 10) * 10 + (year % 100) / 10; if(palmonth > month || (palmonth == month && palday > day))year--; int ansday,ansmonth,ansyear=1e4; int cday,cmonth,cyear; for(cmonth = 1;cmonth < 13;cmonth++) for(cday = 1;cday <= month_len[cmonth];cday++) { cyear = rev(cmonth) * 100 + rev(cday); if(cyear < ansyear && cyear > year) { ansyear = cyear; ansmonth = cmonth; ansday = cday; } } print(ansday,2); print(ansmonth,2); print(ansyear,4); cout<<'\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin>>t; while(t--) solve(); }

Compilation message (stderr)

datum.cpp: In function 'void solve()':
datum.cpp:52:7: warning: 'ansmonth' may be used uninitialized in this function [-Wmaybe-uninitialized]
  print(ansmonth,2);
  ~~~~~^~~~~~~~~~~~
datum.cpp:51:7: warning: 'ansday' may be used uninitialized in this function [-Wmaybe-uninitialized]
  print(ansday,2);
  ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...