Submission #373057

#TimeUsernameProblemLanguageResultExecution timeMemory
373057NimbostratusDatum (COCI20_datum)C++14
50 / 50
32 ms512 KiB
#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) { return x.year == y.year and x.month == y.month and x.day == y.day; } friend bool operator <= (date& x , date& y) { return x < y or x == y; } }; 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)); /*for(date x : vec) { cout << x.day << "." << x.month << "." << x.year << "." << endl; }*/ //cout << endl; 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 (stderr)

datum.cpp: In function 'date datify()':
datum.cpp:69:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |  for(;i<s.size() && s[i] != '.';i++)
      |       ~^~~~~~~~~
datum.cpp:72:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |  for(;i<s.size() && s[i] != '.';i++)
      |       ~^~~~~~~~~
datum.cpp:75:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |  for(;i<s.size() && s[i] != '.';i++)
      |       ~^~~~~~~~~
datum.cpp: In function 'int32_t main()':
datum.cpp:107:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<date>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |   for(i=0;i<vec.size() and vec[i]<=x;i++);
      |           ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...