#include <bits/stdc++.h>
using namespace std;
#define eb emplace_back
#define pb push_back
#define ppb pop_back
#define ub upper_bound
#define lb lower_bound
#define bs binary_search
#define cln(a,s) memset((a),0,sizeof((a)[0])*(s))
#define all(x) (x).begin() , (x).end()
#define fi first
#define se second
#define int int
using pii = pair<int,int>;
using ll = long long;
const int maxn = 2e5 + 5;
const int inf = 1e9;
const int mod = 1e9+7;
class date {
public:
string sday,smonth,syear;
int day,month,year;
date() {
day = inf;
month = inf;
year = inf;
}
date(string& sd,string& sm,string& sy) {
day = stoi(sd);
month = stoi(sm);
year = stoi(sy);
sday = sd;
smonth = sm;
syear = sy;
}
friend bool operator < (date& x , date& y) {
if(x.year < y.year) return true;
if(x.year > y.year) return false;
if(x.month < y.month) return true;
if(x.month > y.month) return false;
return x.day < y.day;
}
friend bool operator <= (date& x , date& y) {
if(x.year <= y.year) return true;
if(x.year > y.year) return false;
if(x.month <= y.month) return true;
if(x.month > y.month) return false;
return x.day <= y.day;
}
};
int n;
string s;
vector<date> vec;
vector<int> days;
bool isvalid(date& x) {
if(x.month == 2 && x.day == 29) return x.year % 4 == 0;
if(x.month > 12 or x.month <= 0) return false;
if(x.day > days[x.month] or x.day <= 0) return false;
return true;
}
date datify() {
string day,month,year;
int i=0;
for(;i<s.size() && s[i] != '.';i++)
day += s[i];
i++;
for(;i<s.size() && s[i] != '.';i++)
month += s[i];
i++;
for(;i<s.size() && s[i] != '.';i++)
year += s[i];
return date(day,month,year);
}
int32_t main () {
//freopen("in","r",stdin); freopen("out","w",stdout);
ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
days = {0,31,28,31,30,31,30,31,31,30,31,30,31};
for(char i='0';i<='3';i++)
for(char j='0';j<='9';j++)
for(char k='0';k<='1';k++)
for(char m='0';m<='9';m++) {
string day = string()+i+j;
string month = string()+k+m;
string year = day + month;
reverse(all(year));
date d(day,month,year);
if(isvalid(d)) {
vec.pb(d);
}
}
sort(all(vec));
cin >> n;
while(n--) {
cin >> s;
date x = datify();
int i;
for(i=0;i<vec.size() and vec[i]<=x;i++);
date d = vec[i];
cout << d.sday << "." << d.smonth << "." << d.syear << "." << endl;
}
}
Compilation message
datum.cpp: In function 'date datify()':
datum.cpp:70:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for(;i<s.size() && s[i] != '.';i++)
| ~^~~~~~~~~
datum.cpp:73:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | for(;i<s.size() && s[i] != '.';i++)
| ~^~~~~~~~~
datum.cpp:76:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
76 | for(;i<s.size() && s[i] != '.';i++)
| ~^~~~~~~~~
datum.cpp: In function 'int32_t main()':
datum.cpp:104:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<date>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
104 | for(i=0;i<vec.size() and vec[i]<=x;i++);
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
492 KB |
Output isn't correct |
2 |
Incorrect |
42 ms |
492 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
492 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
492 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
492 KB |
Output isn't correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Incorrect |
1 ms |
492 KB |
Output isn't correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Incorrect |
33 ms |
748 KB |
Output isn't correct |