Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cmath>
- #include <iostream>
- #include <algorithm>
- #include <string>
- using namespace std;
- int months[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30 ,31, 30, 31};
- const int MAXL = 20;
- int d, m, y;
- string s;
- char c[MAXL];
- int k[MAXL];
- int rec(string s, int n = 0)
- {
- if (n == 3)
- {
- // cout << s << endl;
- int n = s.size() - 1;
- bool f = true;
- for (int i = 1; i + i <= n; i++)
- if (s[i] != s[n - i + 1])
- {
- f = false;
- break;
- }
- if (f) return true;
- int x;
- x = k[1] = 0;
- for (int i = 2; i <= n; i++)
- {
- while (x && s[x + 1] != s[i]) x = k[x];
- x += s[x + 1] == s[i];
- k[i] = x;
- }
- if (x && n % (n - x) == 0) return true;
- return false;
- }
- int x;
- switch (n)
- {
- case 0:
- case 1:
- x = n == 0? d : m;
- sprintf(c, "%02d", x);
- if (rec(s + c, n + 1)) return true;
- if (x < 10)
- {
- sprintf(c, "%d", x);
- if (rec(s + c, n + 1)) return true;
- }
- break;
- case 2:
- sprintf(c, "%d", y);
- if (rec(s + c, n + 1)) return true;
- sprintf(c, "%d", y % 100);
- if (rec(s + c, n + 1)) return true;
- break;
- }
- return false;
- }
- int main()
- {
- freopen("special.in", "r", stdin);
- freopen("special.out", "w", stdout);
- scanf("%d %d %d", &d, &m, &y);
- months[2] = 28 + (int)(y % 400 == 0 || y % 4 == 0 && y % 100 != 0);
- do
- {
- if (rec(" "))
- break;
- d++;
- if (months[m] < d)
- {
- d = 1;
- m++;
- if (12 < m)
- {
- y++;
- m = 1;
- months[2] = 28 + (int)(y % 400 == 0 || y % 4 == 0 && y % 100 != 0);
- }
- }
- } while (true);
- printf("%d %d %d\n", d, m, y);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement