# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
238341 | danikoynov | Datum (COCI20_datum) | C++14 | 47 ms | 504 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<bits/stdc++.h>
#define endl '\n'
using namespace std;
int days(int month, int year)
{
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
return 31;
if (month == 4 || month == 6 || month == 9 || month == 11)
return 30;
if (year % 4 == 0)
return 29;
return 28;
}
bool is_val(int year)
{
int day = year % 10 * 10 + year / 10 % 10;
int month = year / 100 % 10 * 10 + year / 1000 % 10;
if (month > 12 || month < 1)
return false;
if (day < 1 || day > days(month, year))
return false;
if (day < 10)
cout << "0";
cout << day << ".";
if (month < 10)
cout << "0";
cout << month << ".";
if (year < 10)
cout << "0";
if (year < 100)
cout << "0";
if (year < 1000)
cout << "0";
cout << year << "." << endl;
return true;
}
void solve(string s)
{
int sz = s.size();
sz --;
int year = (s[sz - 4] - '0') * 1000 +
(s[sz - 3] - '0') * 100 +
(s[sz - 2] - '0') * 10 +
(s[sz - 1] - '0');
int inday = (s[0] - '0') * 10 + (s[1] - '0');
int inmonth = (s[3] - '0') * 10 + (s[4] - '0');
bool tf = true;
int day = year % 10 * 10 + year / 10 % 10;
int month = year / 100 % 10 * 10 + year / 1000 % 10;
if (month > 12 || month < 1)
tf = false;
if (day < 1 || day > days(month, year))
tf = false;
if (inmonth > month)
tf = false;
if (inmonth == month && inday >= day)
tf = false;
if (tf)
{
if (day < 10)
cout << "0";
cout << day << ".";
if (month < 10)
cout << "0";
cout << month << ".";
if (year < 10)
cout << "0";
if (year < 100)
cout << "0";
if (year < 1000)
cout << "0";
cout << year << "." << endl;
}
else
{
year ++;
while(!is_val(year))
year ++;
}
}
int main()
{
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
string s;
while(n --)
{
cin >> s;
solve(s);
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |