Submission #845143

#TimeUsernameProblemLanguageResultExecution timeMemory
845143vjudge1Datum (COCI20_datum)C++17
0 / 50
1 ms348 KiB
#include <bits/stdc++.h> #define pb push_back #define int int64_t using namespace std; int mp[13] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; constexpr static int M = 100; constexpr static int Y = 10000; bool is_palindrome(const char* s) { for (int i = 0; i < 4; i++) if (s[i] != s[7-i]) return false; return true; } int32_t main() { vector<int> v; for (int y = 1; y <= 9999; y++) { for (int m = 1; m <= 12; m++) { int td = mp[m]; if (m == 2 && ((y%4) == 0)) td = 29; for (int d = 1; d <= td; d++) { char ss[8]; sprintf(ss, "%02d%02d%04d", d, m, y); if (is_palindrome(ss)) v.pb(d + m * M + y * Y); } } } int q; cin >> q; while (q--) { string s; cin >> s; int d = (s[0]-'0') * 10 + (s[1]-'0'), m = (s[3]-'0') * 10 + (s[4]-'0'), y = (s[6]-'0') * 1000 + (s[7]-'0') * 100 + (s[8]-'0') * 10 + (s[9]-'0'); int res = *upper_bound(v.begin(), v.end(), y * Y + m * M + d); cout << res << "\n"; printf("%02d.%02d.%04d.\n", res % M, (res % Y) / M, res / Y); } }

Compilation message (stderr)

datum.cpp: In function 'int32_t main()':
datum.cpp:30:21: warning: format '%d' expects argument of type 'int', but argument 3 has type 'int64_t' {aka 'long int'} [-Wformat=]
   30 |     sprintf(ss, "%02d%02d%04d", d, m, y);
      |                  ~~~^           ~
      |                     |           |
      |                     int         int64_t {aka long int}
      |                  %02ld
datum.cpp:30:25: warning: format '%d' expects argument of type 'int', but argument 4 has type 'int64_t' {aka 'long int'} [-Wformat=]
   30 |     sprintf(ss, "%02d%02d%04d", d, m, y);
      |                      ~~~^          ~
      |                         |          |
      |                         int        int64_t {aka long int}
      |                      %02ld
datum.cpp:30:29: warning: format '%d' expects argument of type 'int', but argument 5 has type 'int64_t' {aka 'long int'} [-Wformat=]
   30 |     sprintf(ss, "%02d%02d%04d", d, m, y);
      |                          ~~~^         ~
      |                             |         |
      |                             int       int64_t {aka long int}
      |                          %04ld
datum.cpp:45:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'int64_t' {aka 'long int'} [-Wformat=]
   45 |   printf("%02d.%02d.%04d.\n", res % M, (res % Y) / M, res / Y);
      |           ~~~^                ~~~~~~~
      |              |                    |
      |              int                  int64_t {aka long int}
      |           %02ld
datum.cpp:45:19: warning: format '%d' expects argument of type 'int', but argument 3 has type 'int64_t' {aka 'long int'} [-Wformat=]
   45 |   printf("%02d.%02d.%04d.\n", res % M, (res % Y) / M, res / Y);
      |                ~~~^                    ~~~~~~~~~~~~~
      |                   |                              |
      |                   int                            int64_t {aka long int}
      |                %02ld
datum.cpp:45:24: warning: format '%d' expects argument of type 'int', but argument 4 has type 'int64_t' {aka 'long int'} [-Wformat=]
   45 |   printf("%02d.%02d.%04d.\n", res % M, (res % Y) / M, res / Y);
      |                     ~~~^                              ~~~~~~~
      |                        |                                  |
      |                        int                                int64_t {aka long int}
      |                     %04ld
datum.cpp:30:30: warning: '__builtin___sprintf_chk' writing a terminating nul past the end of the destination [-Wformat-overflow=]
   30 |     sprintf(ss, "%02d%02d%04d", d, m, y);
      |                              ^
In file included from /usr/include/stdio.h:867,
                 from /usr/include/c++/10/cstdio:42,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:46,
                 from datum.cpp:1:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:36:34: note: '__builtin___sprintf_chk' output between 9 and 18 bytes into a destination of size 8
   36 |   return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
      |          ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   37 |       __bos (__s), __fmt, __va_arg_pack ());
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...