# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
237629 |
2020-06-07T22:51:35 Z |
akat |
Datum (COCI20_datum) |
C++17 |
|
18 ms |
512 KB |
#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,28,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
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 time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Incorrect |
18 ms |
384 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 |
4 ms |
384 KB |
Output is correct |
6 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
512 KB |
Output is correct |
10 |
Correct |
18 ms |
512 KB |
Output is correct |