# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
241987 | stev2005 | Datum (COCI20_datum) | C++17 | 36 ms | 532 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |