solution
stringlengths 11
983k
| difficulty
int64 0
21
| language
stringclasses 2
values |
---|---|---|
#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)3e3 + 1;
int n, m, seq[maxn], idx[maxn], dep[maxn];
vector<int> e[maxn];
bool vis[maxn], ban[maxn];
bool pfs(int u) {
vis[u] = 1;
seq[m++] = u;
for (auto &v : e[u])
if (vis[v]) {
if (m > 1 && v == seq[m - 2]) continue;
for (int i = m - 3; i >= 0; --i)
if (v == seq[i]) {
rotate(seq, seq + i, seq + m);
m -= i;
break;
}
return 1;
} else if (pfs(v)) {
return 1;
}
--m;
vis[u] = 0;
return 0;
}
int f[maxn][maxn], g[maxn][maxn], h[maxn];
int dfs(int u, int fa) {
int su = 1;
f[u][0] = 1;
g[u][0] = 1;
for (auto &v : e[u]) {
if (v == fa || ban[v]) continue;
idx[v] = idx[u];
dep[v] = dep[u] + 1;
int sv = dfs(v, u);
memset(f[u] + su, 0, sv * sizeof(int));
memset(g[u] + su, 0, sv * sizeof(int));
for (int i = 0; i < su; ++i)
if (f[u][i])
for (int j = 0; j < sv; ++j)
if (f[v][j]) g[u][i + j + 1] += 2 * f[u][i] * f[v][j];
for (int i = 0; i < sv; ++i) {
f[u][i + 1] += f[v][i];
g[u][i] += g[v][i];
}
su += sv;
}
return su;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
int u, v;
scanf("%d%d", &u, &v);
e[u].push_back(v);
e[v].push_back(u);
}
pfs(1);
memset(vis, 0, n * sizeof(bool));
for (int i = 0; i < m; ++i) ban[seq[i]] = 1;
for (int i = 0; i < m; ++i) {
idx[seq[i]] = i;
dep[seq[i]] = 0;
int si = dfs(seq[i], -1);
for (int j = 0; j < si; ++j) h[j + 1] += g[seq[i]][j];
}
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
if (idx[i] != idx[j]) {
int u = abs(idx[i] - idx[j]), v = m - u, w = dep[i] + dep[j];
++h[u + w + 1];
++h[v + w + 1];
--h[u + v + w];
}
double ans = 0;
for (int i = 1; i <= n; ++i) ans += (double)h[i] / i;
printf("%.20f\n", ans);
return 0;
}
| 10 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
inline int getint() {
static char c;
while ((c = getchar()) < '0' || c > '9')
;
int res = c - '0';
while ((c = getchar()) >= '0' && c <= '9') res = res * 10 + c - '0';
return res;
}
const int MaxN = 3005;
int n;
int cir_l = 0;
struct halfEdge {
int v, w;
halfEdge *next;
};
halfEdge adj_pool[MaxN * 2], *adj_tail = adj_pool;
halfEdge *adj[MaxN];
inline void addEdge(const int &u, const int &v) {
adj_tail->v = v, adj_tail->w = 0;
adj_tail->next = adj[u], adj[u] = adj_tail++;
}
inline halfEdge *oppo(const halfEdge *e) {
return adj_pool + ((e - adj_pool) ^ 1);
}
inline void set_circle(halfEdge *e, const int &w) { e->w = oppo(e)->w = w; }
int fa[MaxN];
int dfs_clock = 0, dfn[MaxN];
int sta_n = 0;
halfEdge *sta[MaxN];
void dfs(const int &u) {
dfn[u] = ++dfs_clock;
for (halfEdge *e = adj[u]; e; e = e->next) {
if (e->v == fa[u]) continue;
if (!dfn[e->v]) {
sta[++sta_n] = e;
fa[e->v] = u, dfs(e->v);
sta[sta_n--] = NULL;
} else if (dfn[e->v] < dfn[u]) {
++cir_l;
int now = u;
int cur = sta_n;
while (now != e->v) {
set_circle(sta[cur--], 1);
now = fa[now];
++cir_l;
}
set_circle(e, -1);
}
}
}
int sum[MaxN];
int cir[MaxN];
int q_n = 0, q[MaxN];
double res = 0.0;
inline void bfs(const int &sv) {
for (int u = 1; u <= n; ++u) sum[u] = cir[u] = -1;
sum[sv] = cir[sv] = 0;
q[q_n = 1] = sv;
for (int i = 1; i <= q_n; ++i) {
int u = q[i];
if (!cir[u])
res += 1.0 / (sum[u] + 1.0);
else {
int cir_vl = cir[u] - 1;
int cir_vr = cir_l - cir[u] - 1;
int l = sum[u] - cir[u] + 2;
res += 1.0 / (l + cir_vl);
res += 1.0 / (l + cir_vr);
res -= 1.0 / (l + cir_vl + cir_vr);
}
for (halfEdge *e = adj[u]; e; e = e->next) {
if (e->w == -1 || sum[e->v] != -1) continue;
sum[e->v] = sum[u] + 1;
cir[e->v] = cir[u] + e->w;
q[++q_n] = e->v;
}
}
}
int main() {
n = getint();
for (int i = 1; i <= n; ++i) {
int u = getint() + 1, v = getint() + 1;
addEdge(u, v);
addEdge(v, u);
}
dfs(1);
for (int u = 1; u <= n; ++u) bfs(u);
printf("%.16f\n", res);
return 0;
}
| 10 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
int head[N], from[N], to[N << 2], nxt[N << 2], dep[N], q[N], vis[N], bel[N],
num[N << 2], cnt;
double ans;
int tot, x, y, n, m;
int f[N][25];
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + (ch ^ 48);
ch = getchar();
}
return x * f;
}
inline void add(int u, int v, int w) {
nxt[++cnt] = head[u];
head[u] = cnt;
to[cnt] = v;
num[cnt] = w;
}
bool dfs(int u, int fa) {
vis[u] = 1;
for (int i = head[u]; i; i = nxt[i]) {
if (num[i] != fa) {
if (vis[to[i]]) {
for (int j = u; j != to[i]; j = from[j]) q[++tot] = j;
q[++tot] = to[i];
return true;
} else {
from[to[i]] = u;
if (dfs(to[i], num[i])) return true;
}
}
}
return false;
}
void find(int u, int fa, int rt) {
bel[u] = rt;
dep[u] = dep[fa] + 1;
f[u][0] = fa;
for (int i = 1; i <= 15; i++) f[u][i] = f[f[u][i - 1]][i - 1];
for (int i = head[u]; i; i = nxt[i])
if (to[i] != fa && !vis[to[i]]) find(to[i], u, rt);
}
int lca(int x, int y) {
if (dep[x] < dep[y]) swap(x, y);
int dis = dep[x] - dep[y];
for (int i = 0; i <= 15; i++)
if (dis & (1 << i)) x = f[x][i];
if (x == y) return x;
for (int i = 15; i >= 0; i--)
if (f[x][i] != f[y][i]) x = f[x][i], y = f[y][i];
return f[x][0];
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d%d", &x, &y);
x++;
y++;
add(x, y, i);
add(y, x, i);
}
dfs(1, 0);
memset(vis, 0, sizeof(vis));
for (int i = 1; i <= tot; i++) vis[q[i]] = 1;
for (int i = 1; i <= tot; i++) find(q[i], 0, i);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if (bel[i] == bel[j])
ans += (double)1 / (dep[i] + dep[j] - 2 * dep[lca(i, j)] + 1);
else {
int X = dep[i] + dep[j];
int Y = abs(bel[i] - bel[j]) - 1;
int Z = tot - Y - 2;
ans +=
(double)1 / (X + Y) + (double)1 / (X + Z) - (double)1 / (X + Y + Z);
}
printf("%.7f", ans);
return 0;
}
| 10 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
int szm[3100][3100];
int numd;
int sizc;
int totb;
int hc;
struct nodeb {
int next;
int v;
};
nodeb szb[3100 << 1];
struct noded {
bool inc;
bool vis;
int next;
int ind;
int top;
};
noded szd[3100];
void adde(int from, int to) {
totb++;
szb[totb].v = to;
szb[totb].next = szd[from].ind;
szd[from].ind = totb;
return;
}
bool dfs1(int x, int fa) {
int f1;
szd[x].vis = true;
for (f1 = szd[x].ind; f1 != 0; f1 = szb[f1].next) {
if (szb[f1].v == fa) continue;
if (szd[szb[f1].v].vis) {
szd[szb[f1].v].inc = true;
szd[x].inc = true;
return true;
}
if (dfs1(szb[f1].v, x)) break;
}
if ((f1 == 0) || (szd[x].inc)) return false;
szd[x].inc = true;
return true;
}
void dfs2(int x, int fa, int top, int deep) {
int f1;
szm[top][x] = szm[x][top] = deep;
if (szd[top].inc) szd[x].top = top;
for (f1 = szd[x].ind; f1 != 0; f1 = szb[f1].next)
if ((szb[f1].v != fa) && (szd[szb[f1].v].inc == false))
dfs2(szb[f1].v, x, top, deep + 1);
return;
}
void dfs3(int x, int fa) {
int f1;
if (szd[x].next != 0) return;
for (f1 = szd[x].ind; f1 != 0; f1 = szb[f1].next)
if ((szb[f1].v != fa) && szd[szb[f1].v].inc) {
szd[x].next = szb[f1].v;
dfs3(szb[f1].v, x);
break;
}
return;
}
int main() {
double ans;
int w1;
int w2;
int f1;
int f2;
int f3;
scanf("%d", &numd);
for (f1 = 1; f1 <= numd; f1++) {
scanf("%d%d", &w1, &w2);
w1++;
w2++;
adde(w1, w2);
adde(w2, w1);
}
dfs1(1, 0);
for (f1 = 1; f1 <= numd; f1++) {
dfs2(f1, 0, f1, 0);
if (szd[f1].inc) {
if (sizc == 0) {
dfs3(f1, 0);
hc = f1;
}
sizc++;
for (f2 = 1; f2 <= numd; f2++) szm[f2][f1] = szm[f1][f2];
}
}
f1 = hc;
do {
for (f2 = szd[f1].next, f3 = 1; f2 != f1; f2 = szd[f2].next, f3++)
szm[f1][f2] = f3;
f1 = szd[f1].next;
} while (f1 != hc);
ans = 0;
for (f1 = 1; f1 <= numd; f1++)
for (f2 = 1; f2 <= numd; f2++)
if (szd[f1].top == szd[f2].top)
if ((szm[f1][f2] != 0) || (f1 == f2))
ans += (double)1 / (szm[f1][f2] + 1);
else
ans += (double)1 / (szm[f1][szd[f1].top] + szm[f2][szd[f2].top] + 1);
else {
ans += (double)1 / (szm[f1][szd[f1].top] + szm[f2][szd[f2].top] +
szm[szd[f1].top][szd[f2].top] + 1);
ans += (double)1 / (szm[f1][szd[f1].top] + szm[f2][szd[f2].top] +
(sizc - szm[szd[f1].top][szd[f2].top]) + 1);
ans -= (double)1 / (szm[f1][szd[f1].top] + szm[f2][szd[f2].top] + sizc);
}
printf("%.10lf\n", ans);
return 0;
}
| 10 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
const int N = 3 * 1e3 + 10;
int v[N << 1];
int x[N << 1];
int ct;
int al[N];
bool isr[N];
int n;
int tot;
int ed;
int st;
double ans;
inline void add(int u, int V) {
v[++ct] = V;
x[ct] = al[u];
al[u] = ct;
}
struct bcj {
int fa[N];
inline void ih() {
for (int i = 1; i <= n; i++) fa[i] = i;
}
inline int f(int x) { return fa[x] = (fa[x] == x) ? x : f(fa[x]); }
inline bool u(int x, int y) {
x = f(x);
y = f(y);
if (x == y) return false;
fa[x] = y;
return true;
}
} s;
inline void dfs(int u, int f, int dep1, int dep2) {
dep1++;
dep2 += isr[u];
if (dep2 == 0 || dep2 == 1)
ans += 1.0 / (dep1);
else {
ans += 1.0 / dep1;
ans += 1.0 / (dep1 - dep2 + (tot - dep2));
ans -= 1.0 / (dep1 + (tot - dep2 - 2));
}
for (int i = al[u]; i; i = x[i])
if (v[i] != f) dfs(v[i], u, dep1, dep2);
}
inline bool mrk(int u, int tar, int f) {
if (u == tar) {
return isr[u] = true;
}
for (int i = al[u]; i; i = x[i])
if (v[i] != f)
if (mrk(v[i], tar, u)) return isr[u] = true;
return false;
}
int main() {
scanf("%d", &n);
s.ih();
for (int i = 1, u, v; i <= n; i++) {
scanf("%d%d", &u, &v);
u++;
v++;
if (s.u(u, v) == false)
st = u, ed = v;
else
add(u, v), add(v, u);
}
mrk(st, ed, 0);
for (int i = 1; i <= n; i++) tot += isr[i];
tot += 2;
for (int i = 1; i <= n; i++) {
dfs(i, 0, 0, 0);
}
printf("%.10lf", ans);
return 0;
}
| 10 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
struct apple {
int v, nxt;
} edge[3011 * 4];
double ans;
int n, len, indexx[3011], a[3011], cir[3011], belong[3011], fa[3011][20 + 1],
tot, vist[3011], rt, deep[3011];
void addedge(int x, int y) {
edge[++tot].v = y;
edge[tot].nxt = indexx[x];
indexx[x] = tot;
}
int find_cir(int u, int pre) {
if (vist[u]) {
rt = u;
return 2;
}
vist[u] = 1;
int t = indexx[u], vv;
while (t) {
vv = edge[t].v;
if (t != ((pre - 1) ^ 1) + 1) {
int k = find_cir(vv, t);
if (k == 2) {
a[++len] = u;
cir[u] = 1;
if (u == rt) return 1;
return 2;
} else if (k == 1)
return 1;
}
t = edge[t].nxt;
}
return 0;
}
void dfs(int u, int Fa, int anc, int dep) {
belong[u] = anc;
deep[u] = dep;
fa[u][0] = Fa;
int t = indexx[u], vv;
while (t) {
vv = edge[t].v;
if (vv != Fa && !cir[vv]) {
dfs(vv, u, anc, dep + 1);
}
t = edge[t].nxt;
}
}
int lca(int x, int y) {
if (deep[x] < deep[y]) swap(x, y);
for (int i = 20; i >= 0; i--) {
if (deep[fa[x][i]] >= deep[y]) x = fa[x][i];
}
if (x == y) return x;
int ret = 0;
for (int i = 20; i >= 0; i--) {
if (fa[x][i] == fa[y][i])
ret = fa[x][i];
else
x = fa[x][i], y = fa[y][i];
}
return ret;
}
void solve() {
int x, y, z;
for (int i = 1; i <= len; i++) {
dfs(a[i], 0, i, 1);
}
for (int i = 1; i <= 20; i++) {
for (int j = 1; j <= n; j++) fa[j][i] = fa[fa[j][i - 1]][i - 1];
}
ans = n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (i == j) continue;
if (belong[i] == belong[j]) {
x = deep[i] + deep[j] - 2 * deep[lca(i, j)] + 1;
ans += (1 / (double)x);
} else {
x = deep[i] + deep[j];
y = abs(belong[i] - belong[j]) - 1;
z = len - y - 2;
ans += (1.0 / (x + y) + 1.0 / (x + z) - 1.0 / (x + y + z));
}
}
}
}
int main() {
int x, y;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d%d", &x, &y);
x++, y++;
addedge(x, y);
addedge(y, x);
}
find_cir(1, 0);
solve();
printf("%lf", ans);
return 0;
}
| 10 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void chkmax(T& x, U y) {
if (x < y) x = y;
}
template <typename T, typename U>
inline void chkmin(T& x, U y) {
if (y < x) x = y;
}
vector<int> V;
double ans;
const int MAXN = 3333;
int T;
int par[MAXN], vis[MAXN], dis[MAXN];
vector<int> adj[MAXN];
void dfs(int u, int p) {
vis[u] = ++T, par[u] = p;
for (int i = 0; i < adj[u].size(); i++) {
int v = adj[u][i];
if (v == p) continue;
if (!vis[v]) {
dfs(v, u);
} else {
if (vis[v] < vis[u]) {
V.push_back(v);
for (int w = u; w != v; V.push_back(w), w = par[w])
;
}
}
}
}
void dfs1(int u, int p, int d) {
vis[u] = T, dis[u] = d;
if (d > 1) ans += 1.0 / d;
for (int i = 0; i < adj[u].size(); i++) {
int v = adj[u][i];
if (v == p) continue;
dfs1(v, u, d + 1);
}
}
vector<int> W;
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
int u, v;
scanf("%d%d", &u, &v), u++, v++;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(1, 0);
for (int i = 0; i < V.size(); i++) {
int j = (i + 1) % V.size();
adj[V[i]].erase(find((adj[V[i]]).begin(), (adj[V[i]]).end(), V[j]));
adj[V[j]].erase(find((adj[V[j]]).begin(), (adj[V[j]]).end(), V[i]));
}
ans = n + 3 - ((int)(V.size()));
for (int i = 1; i <= n; i++) {
bool flg = 1;
for (int j = 0; flg && j < V.size(); j++)
if (i == V[j]) flg = 0;
if (flg) dfs1(i, 0, 1);
}
memset(vis, 0, sizeof vis), T = 0;
for (int i = 0; i < V.size(); i++) dfs1(V[i], 0, 1), T++;
for (int i = 1; i <= n; i++) {
if (dis[i] == 1) continue;
for (int j = i + 1; j <= n; j++) {
if (dis[j] == 1) continue;
if (vis[i] == vis[j] || vis[i] == (vis[j] + 1) % V.size() ||
vis[j] == (vis[i] + 1) % V.size())
continue;
ans -= 2.0 / (dis[i] + dis[j] - 2 + V.size());
}
}
for (int i = 1; i <= n; i++) {
if (dis[i] == 1) continue;
ans -= 2.0 * (((int)(V.size())) - 3) / (dis[i] - 1 + V.size());
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (vis[i] == vis[j] || vis[i] == (vis[j] + 1) % V.size()) continue;
ans +=
2.0 / (dis[i] + dis[j] +
(vis[j] - vis[i] + ((int)(V.size())) - 1) % ((int)(V.size())));
}
}
printf("%.10lf\n", ans);
return 0;
}
| 10 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
inline int read() {
bool f = true;
register int x = 0;
char ch;
while (!isdigit(ch = getchar()))
if (ch == '-') f = false;
while (isdigit(ch)) {
x = (x << 1) + (x << 3) + ch - '0';
ch = getchar();
}
return f ? x : -x;
}
double ans;
int n, cnt, C, H, T;
int q[3005], d[3005], d2[3005];
bool vis[3005];
vector<int> e[3005];
void dfs(int x) {
vis[x] = 1;
for (int i = 0; i < e[x].size(); i++) {
int b = e[x][i];
if (!vis[b]) {
d2[b] = d2[x] + 1;
if (!d[b]) {
d[b] = d[x] + 1;
ans += 1.0 / d[b];
} else
ans = ans + 1.0 / d2[b] - 2.0 / (d[b] + d2[b] + C - 2);
dfs(b);
}
}
vis[x] = 0;
}
int main() {
n = read();
for (int i = 1, u, v; i <= n; i++) {
u = read() + 1;
v = read() + 1;
e[u].push_back(v);
e[v].push_back(u);
d[u]++;
d[v]++;
}
for (int i = 1; i <= n; i++)
if (d[i] == 1) q[T++] = i;
while (H != T) {
int now = q[H];
H++;
for (int i = 0; i < e[now].size(); i++) {
int b = e[now][i];
d[b]--;
if (d[b] == 1) {
q[T++] = b;
}
}
}
C = n - T;
for (int i = 1; i <= n; i++) {
memset(d, 0, sizeof(d));
memset(d2, 0, sizeof(d2));
d[i] = d2[i] = 1;
dfs(i);
}
printf("%.10lf\n", ans + n);
return 0;
}
| 10 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3005;
vector<int> p[MAXN];
int n;
double ans = 0;
bool instack[MAXN];
int rd[MAXN];
int circle;
int q[MAXN];
inline void TopSort() {
for (int i = (0); i <= (int)n - 1; i++)
if (rd[i] == 1) q[++q[0]] = i;
for (int i = (1); i <= (int)q[0]; i++) {
int x = q[i];
for (int j = (0); j <= (int)p[x].size() - 1; j++)
if ((--rd[p[x][j]]) == 1) q[++q[0]] = p[x][j];
}
circle = n - q[0];
}
int d1[MAXN], d2[MAXN];
void dfs(int x, int d) {
if (!d1[x])
d1[x] = d;
else
d2[x] = d;
instack[x] = 1;
for (int i = (0); i <= (int)p[x].size() - 1; i++)
if (!instack[p[x][i]]) dfs(p[x][i], d + 1);
instack[x] = 0;
}
int main() {
scanf("%d", &n);
for (int i = (1); i <= (int)n; i++) {
int a, b;
scanf("%d%d", &a, &b);
p[a].push_back(b);
p[b].push_back(a);
rd[a]++;
rd[b]++;
}
TopSort();
for (int i = (0); i <= (int)n - 1; i++) {
memset(d1, 0, sizeof d1);
memset(d2, 0, sizeof d2);
dfs(i, 1);
for (int j = (0); j <= (int)n - 1; j++)
if (!d2[j])
ans += 1. / d1[j];
else
ans += (1. / d1[j]) + (1. / d2[j]) -
(1. / ((d1[j] + d2[j] + circle - 2) / 2));
}
printf("%.10lf\n", ans);
return 0;
}
| 10 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3000;
vector<int> g[maxn + 50];
queue<int> q;
int d[maxn + 50], d1[maxn + 50];
bool vis[maxn + 50];
int x, y, n, l = 0;
double ans = 0.0;
void dfs(int k) {
vis[k] = 1;
for (int i = 0; i < g[k].size(); ++i)
if (!vis[g[k][i]]) {
d[g[k][i]] = d[k] + 1;
if (!d1[g[k][i]])
d1[g[k][i]] = d[g[k][i]], ans += 1.0 / d[g[k][i]];
else
ans += 1.0 / d[g[k][i]] - 2.0 / (d[g[k][i]] + d1[g[k][i]] + l - 2);
dfs(g[k][i]);
}
vis[k] = 0;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) g[i].clear();
memset(d, 0, sizeof(d));
for (int i = 1; i <= n; ++i)
scanf("%d%d", &x, &y), ++x, ++y, g[x].push_back(y), g[y].push_back(x),
++d[x], ++d[y];
while (!q.empty()) q.pop();
for (int i = 1; i <= n; ++i)
if (d[i] == 1) q.push(i);
l = n;
while (!q.empty()) {
--l;
int u = q.front();
q.pop();
for (int i = 0; i < g[u].size(); ++i)
if (--d[g[u][i]] == 1) q.push(g[u][i]);
}
for (int i = 1; i <= n; ++i) {
memset(d1, 0, sizeof(d1));
memset(d, 0, sizeof(d));
memset(vis, 0, sizeof(vis));
d1[i] = d[i] = 1;
dfs(i);
}
printf("%.10f", ans + n);
return 0;
}
| 10 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
int n, S[5010], dis1[5010], dis2[5010], Head[5010], Next[10010], Go[10010],
Cnt = 0, Top = 0, Where[5010], Cycle = 0;
bool Vis[5010];
double ans = 0.0;
inline void addedge(int x, int y) {
Go[++Cnt] = y;
Next[Cnt] = Head[x];
Head[x] = Cnt;
}
void Find(int x, int before = 0) {
S[++Top] = x;
if (Where[x]) {
for (int i = Where[x]; i < Top; i++) Cycle++;
return;
}
Where[x] = Top;
for (int T = Head[x]; T; T = Next[T])
if (Go[T] != before) Find(Go[T], x);
Top--;
}
void dfs(int x, int k) {
if (k) (!dis1[x]) ? dis1[x] = k, dis2[x] = 0 : dis2[x] = k;
Vis[x] = 1;
for (int T = Head[x]; T; T = Next[T])
if (!Vis[Go[T]]) dfs(Go[T], k + 1);
Vis[x] = 0;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
int x, y;
scanf("%d%d", &x, &y);
addedge(x, y);
addedge(y, x);
}
Find(1);
for (int i = 0; i < n; i++) {
memset(Vis, 0, sizeof Vis);
memset(dis1, 0, sizeof dis1);
dfs(i, 1);
for (int j = 0; j < n; j++)
if (j != i)
ans += (dis2[j]) ? 1.0 / dis1[j] + 1.0 / dis2[j] -
2.0 / (dis1[j] + dis2[j] + Cycle - 2)
: 1.0 / dis1[j];
}
printf("%.12lf\n", ans + n);
return 0;
}
| 10 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long double pi = acosl(-1);
const long long infl = 1e17 + 100;
const int inf = 1e9 + 100;
const int nmax = 3000 + 10;
const int MAXLG = log2(nmax) + 1;
vector<int> g[nmax];
int depth[nmax];
int par[nmax];
int LCA[nmax][nmax];
int recc(int u, int v) {
if (u == v) return u;
if (LCA[u][v] != 0) return LCA[u][v];
if (depth[u] < depth[v]) swap(u, v);
if (depth[u] != depth[v]) return LCA[u][v] = recc(par[u], v);
return LCA[u][v] = recc(par[u], par[v]);
}
int dist(int u, int v) {
int w = recc(u, v);
if (w < 0) {
cout << "jahmela fr " << u << " " << v << endl;
}
return -depth[w] + depth[u] - depth[w] + depth[v];
}
int cycnod[nmax];
int getrut[nmax];
void dfs(int u, int level, int rut, int p = -1) {
depth[u] = level;
par[u] = p;
getrut[u] = rut;
for (int v : g[u])
if (v != p and !cycnod[v]) dfs(v, level + 1, rut, u);
}
bool vis[nmax];
vector<int> saicel;
bool done;
void dfs0(int u, int p = -1) {
vis[u] = true;
par[u] = p;
for (int v : g[u])
if (v != p) {
if (vis[v]) {
int cur = u;
cycnod[v] = true;
saicel.push_back(v);
while (cur != v)
cycnod[cur] = true, saicel.push_back(cur), cur = par[cur];
done = true;
} else
dfs0(v, u);
if (done) return;
}
}
int D[nmax][nmax];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
long double ans = 0.0;
dfs0(0);
for (int i = 0; i < saicel.size(); i++)
for (int j = 0; j < saicel.size(); j++)
D[saicel[i]][saicel[j]] = abs(i - j);
for (int i = 0; i < n; i++)
if (cycnod[i]) dfs(i, 0, i);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
if (getrut[i] == getrut[j]) {
ans += 1.0 / (dist(i, j) + 1);
} else {
double X = depth[i] + depth[j] + 2;
int ri = getrut[i], rj = getrut[j];
double Y = D[ri][rj];
double Z = (int)saicel.size() - Y;
Y -= 1.0, Z -= 1.0;
ans += 1.0 / (X + Y) + 1.0 / (X + Z) - 1.0 / (X + Y + Z);
}
}
cout << fixed << setprecision(12) << ans << endl;
}
| 10 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char p = getchar();
while (!isdigit(p)) {
if (p == '-') f = -1;
p = getchar();
}
while (isdigit(p)) x = (x << 3) + (x << 1) + (p ^ 48), p = getchar();
return x * f;
}
const int maxn = 3e3 + 5;
int n, head[maxn], ver[maxn << 1], nxt[maxn << 1], f[maxn][14], tot;
int dep[maxn], d[maxn], a[maxn], col[maxn], cir[maxn];
int vis[maxn], cnt = 1, stk[maxn], top;
double ans;
inline void add(int x, int y) {
nxt[++cnt] = head[x];
head[x] = cnt;
ver[cnt] = y;
}
inline bool find_circle(int x, int fr) {
if (vis[x]) {
int tmp = 0;
do {
a[++tot] = tmp = stk[top--];
} while (x != tmp);
return 1;
}
stk[++top] = x;
vis[x] = 1;
for (int i = head[x]; i; i = nxt[i]) {
if (i == (fr ^ 1)) continue;
int y = ver[i];
if (find_circle(y, i)) return 1;
}
vis[stk[top--]] = 0;
return 0;
}
inline int lca(int x, int y) {
if (dep[x] < dep[y]) swap(x, y);
for (int i = 13; i >= 0; i--)
if ((dep[x] - dep[y]) >= 1 << i) x = f[x][i];
if (x == y) return x;
for (int i = 13; i >= 0; i--)
if (f[x][i] != f[y][i]) x = f[x][i], y = f[y][i];
return f[x][0];
}
inline int dis(int x, int y) { return dep[x] + dep[y] - 2 * dep[lca(x, y)]; }
inline void dfs(int x, int fa, int rt) {
col[x] = rt;
dep[x] = dep[fa] + 1;
f[x][0] = fa;
for (int i = head[x]; i; i = nxt[i]) {
int y = ver[i];
if (y == fa) continue;
dfs(y, x, rt);
}
}
inline void pre_work() {
for (int j = 1; j <= 13; j++)
for (int i = 1; i <= n; i++) f[i][j] = f[f[i][j - 1]][j - 1];
}
int main() {
n = read();
for (int i = 1, x, y; i <= n; i++)
x = read() + 1, y = read() + 1, add(x, y), add(y, x);
find_circle(1, -1);
memset(vis, 0, sizeof(vis));
for (int i = 1; i <= tot; i++) vis[a[i]] = 1;
for (int j = 1; j <= tot; j++) {
int x = a[j];
for (int i = head[x]; i; i = nxt[i]) {
int y = ver[i];
if (vis[y]) continue;
dfs(y, x, x);
}
}
pre_work();
for (int i = 1; i <= tot; i++) d[a[i]] = i - 1;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) {
if (i == j) {
ans += 1;
continue;
}
int w = 0;
if (vis[i]) w++;
if (vis[j]) w++;
if (w == 0) {
if (col[i] == col[j]) {
ans += 1.0 / (dis(i, j) + 1);
continue;
}
int e = dep[i] + dep[j] + tot;
int r = dep[i] + dep[j] + abs(d[col[i]] - d[col[j]]) + 1;
int t = dep[i] + dep[j] + tot - abs(d[col[i]] - d[col[j]]) + 1;
ans += 1.0 / r;
ans += 1.0 / t;
ans -= 1.0 / e;
}
if (w == 1) {
int x = i, y = j;
if (vis[j]) swap(x, y);
if (col[y] == x) {
ans += 1.0 / (dep[y] + 1);
continue;
}
int e = dep[y] + tot;
int r = dep[y] + abs(d[x] - d[col[y]]) + 1;
int t = dep[y] + tot - abs(d[x] - d[col[y]]) + 1;
ans += 1.0 / r;
ans += 1.0 / t;
ans -= 1.0 / e;
}
if (w == 2) {
int e = tot;
int r = abs(d[i] - d[j]) + 1;
int t = tot - abs(d[i] - d[j]) + 1;
ans += 1.0 / r;
ans += 1.0 / t;
ans -= 1.0 / e;
}
}
printf("%.8f\n", ans);
return 0;
}
| 10 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
int head[100005];
struct edge {
int vet, next;
} E[200005];
int i, j, k, n, m, s, t, tot, L;
int top[100005];
int fa[100005];
int dep[100005];
int a[100005];
int dist[3005][3005];
double ans;
int X, Y, all;
int cyc[100005];
int getf(int x) {
if (x != fa[x]) fa[x] = getf(fa[x]);
return fa[x];
}
void add(int u, int v) {
E[++tot] = (edge){v, head[u]};
head[u] = tot;
}
void getroad(int u, int dad) {
if (u == Y) {
L = cyc[u] = 1;
return;
}
for (int e = head[u]; e != -1; e = E[e].next)
if (e != dad) {
getroad(E[e].vet, e ^ 1);
if (cyc[E[e].vet] > 0) {
cyc[u] = cyc[E[e].vet] + 1;
L = max(L, cyc[u]);
}
}
}
void dfs(int u, const int &anc, int dad, int deep) {
dep[u] = deep;
top[u] = anc;
for (int e = head[u]; e != -1; e = E[e].next)
if (e != dad && cyc[E[e].vet] == 0) dfs(E[e].vet, anc, e ^ 1, deep + 1);
}
void getdis(int u, const int &anc, int dad, int D) {
dist[anc][u] = D;
for (int e = head[u]; e != -1; e = E[e].next)
if (e != dad) getdis(E[e].vet, anc, e ^ 1, D + 1);
}
void DO() {
for (int i = 1; i <= n; i++) getdis(i, i, -1, 0);
}
int main() {
tot = -1;
memset(head, -1, sizeof(head));
scanf("%d", &n);
for (int i = 1; i <= n; i++) fa[i] = i;
for (int i = 1; i <= n; i++) {
int x, y;
scanf("%d%d", &x, &y);
x++;
y++;
if (getf(x) == getf(y)) {
X = x;
Y = y;
continue;
}
add(x, y);
add(y, x);
fa[getf(x)] = getf(y);
}
DO();
getroad(X, -1);
for (int i = 1; i <= n; i++)
if (cyc[i] > 0) dfs(i, i, -1, 0);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if (i != j) {
if (top[i] == top[j])
ans += 1.0 / (dist[i][j] + 1);
else {
int x = dep[i] + dep[j];
int y = abs(cyc[top[i]] - cyc[top[j]]);
int z = L - y;
ans += 1.0 / (x + y + 1) + 1.0 / (x + z + 1) - 1.0 / (x + L);
}
}
ans += n;
printf("%.14f\n", ans);
return 0;
}
| 10 |
CPP
|
#include <bits/stdc++.h>
template <typename T>
inline void read(T &x) {
x = 0;
char c = getchar();
bool flag = false;
while (!isdigit(c)) {
if (c == '-') flag = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
if (flag) x = -x;
}
using namespace std;
int n;
struct edge {
int nxt;
int to;
} e[4223 << 1];
int head[4223], ecnt = 1;
inline void addedge(int from, int to) {
e[++ecnt] = (edge){head[from], to};
head[from] = ecnt;
}
int d[4223];
int que[4223 << 1], front, rear;
bool notcir[4223];
bool incir[4223 << 1];
inline void topo() {
for (register int i = 1; i <= n; ++i)
if (d[i] == 1) que[++rear] = i, notcir[i] = true;
while (front < rear) {
int cur = que[++front];
for (register int i = head[cur]; i; i = e[i].nxt) {
int to = e[i].to;
if (notcir[to]) continue;
--d[to];
if (d[to] == 1) {
notcir[to] = true;
que[++rear] = to;
}
}
}
for (register int p = 1; p <= n; ++p)
if (!notcir[p]) {
for (register int i = head[p]; i; i = e[i].nxt) {
int to = e[i].to;
if (notcir[to]) continue;
incir[i] = true;
}
}
}
double f[4223][4223];
void dfs_in_tree(int u, int cur, int depp, int faa) {
f[u][cur] = f[cur][u] = 1.0 / depp;
for (register int i = head[cur]; i; i = e[i].nxt) {
int to = e[i].to;
if (incir[i] || to == faa) continue;
dfs_in_tree(u, to, depp + 1, cur);
}
}
int h[4223], htot;
bool vis[4223];
void find_cir(int cur) {
h[++htot] = cur;
vis[cur] = true;
for (register int i = head[cur]; i; i = e[i].nxt)
if (incir[i]) {
int to = e[i].to;
if (!vis[to]) find_cir(to);
}
}
void dfs3(int cur, int u, int y, int z, int x, int faa) {
f[cur][u] = f[u][cur] = 1.0 / (x + y) + 1.0 / (x + z) - 1.0 / (x + y + z);
for (register int i = head[cur]; i; i = e[i].nxt)
if (!incir[i]) {
int to = e[i].to;
if (to == faa) continue;
dfs3(to, u, y, z, x + 1, cur);
}
}
void dfs2(int cur, int v, int y, int z, int x, int faa) {
dfs3(v, cur, y, z, x + 1, 0);
for (register int i = head[cur]; i; i = e[i].nxt)
if (!incir[i]) {
int to = e[i].to;
if (to == faa) continue;
dfs2(to, v, y, z, x + 1, cur);
}
}
inline void Cir() {
for (register int i = 1; i <= n; ++i) {
if (!notcir[i]) {
find_cir(i);
break;
}
}
for (register int i = 1; i <= htot; ++i) {
for (register int j = i + 1; j <= htot; ++j) {
dfs2(h[i], h[j], j - i - 1, htot - j + i - 1, 1, 0);
}
}
}
int main() {
read(n);
for (register int i = 1; i <= n; ++i) {
int u, v;
read(u), read(v);
++u, ++v;
addedge(u, v), addedge(v, u);
++d[u], ++d[v];
}
topo();
for (register int i = 1; i <= n; ++i) {
dfs_in_tree(i, i, 1, 0);
}
Cir();
double res = 0;
for (register int i = 1; i <= n; ++i) {
for (register int j = 1; j <= n; ++j) {
res += f[i][j];
}
}
printf("%.10lf\n", res);
return 0;
}
| 10 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
char s[100005];
int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
map<string, int> my;
void check(char* s) {
if (((s[0]) >= '0' && (s[0]) <= '9') && ((s[1]) >= '0' && (s[1]) <= '9') &&
((s[3]) >= '0' && (s[3]) <= '9') && ((s[4]) >= '0' && (s[4]) <= '9') &&
((s[6]) >= '0' && (s[6]) <= '9') && ((s[7]) >= '0' && (s[7]) <= '9') &&
((s[8]) >= '0' && (s[8]) <= '9') && ((s[9]) >= '0' && (s[9]) <= '9') &&
s[2] == '-' && s[5] == '-') {
int d = atoi(s);
int m = atoi(s + 3);
int y = atoi(string(s + 6, s + 10).c_str());
if (m <= 12 && d > 0 && d <= day[m - 1] && y >= 2013 && y <= 2015) {
++my[string(s, s + 10)];
}
}
}
int main() {
gets(s);
int n = strlen(s);
for (int i = 0; i + 10 <= n; ++i) check(s + i);
string res("");
int max = -1;
for (typeof((my).begin()) it = (my).begin(), _e = (my).end(); it != _e; ++it)
if (it->second > max) {
max = it->second;
res = it->first;
}
cout << res << endl;
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
int occ[40][20][10];
bool isNumber(char c) { return (48 <= int(c) && int(c) <= 57); }
int sti(string s) {
int ans = 0;
for (int i = 0; i < s.length(); i++) ans = ans * 10 + int(s[i]) - 48;
return ans;
}
int date[20] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool isDate(string s, int &d, int &m, int &y) {
if (isNumber(s[0]) && isNumber(s[1]) && s[2] == '-' && isNumber(s[3]) &&
isNumber(s[4]) && s[5] == '-' && s[6] == '2' && s[7] == '0' &&
s[8] == '1' && isNumber(s[9])) {
d = sti(s.substr(0, 2));
m = sti(s.substr(3, 2));
y = sti(s.substr(6, 4));
if (2013 <= y && y <= 2015 && 1 <= m && m <= 12 && 1 <= d && d <= date[m])
return true;
}
return false;
}
int main() {
string s;
cin >> s;
for (int i = 0; i < s.length() - 9; i++) {
int d, m, y;
if (isDate(s.substr(i, 10), d, m, y)) {
occ[d][m][y - 2013]++;
}
}
int Max = 0, yans, dans, mans;
for (int y = 0; y <= 2; y++)
for (int m = 1; m <= 12; m++)
for (int d = 1; d <= date[m]; d++)
if (occ[d][m][y] > Max) {
Max = occ[d][m][y];
yans = y;
mans = m;
dans = d;
}
if (dans < 10) cout << 0;
cout << dans << "-";
if (mans < 10) cout << 0;
cout << mans << "-";
cout << yans + 2013 << endl;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
void gt(int &a, int b) {
if (a < b) a = b;
}
string n2s(int a) {
stringstream ss;
ss << a;
return ss.str();
}
int days[]{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool isValidDate(string str) {
int d, m, y;
char ch;
for (int i = 0; i <= 8; i++) {
if (i == 2 || i == 5) {
if (str[i] != '-') return false;
continue;
}
if (!isdigit(str[i])) return false;
}
stringstream ss;
ss << str;
ss >> d >> ch >> m >> ch >> y;
if (y < 2013 || y > 2015) return false;
if (m < 1 || m > 12) return false;
return d <= days[m] && d > 0;
}
map<string, int> m;
int main() {
string str, temp, ans = "";
int max = 0;
cin >> str;
for (int i = 0; i <= str.length() - 10; i++) {
temp = str.substr(i, 10);
if (isValidDate(temp)) {
if (m.find(temp) == m.end()) {
m[temp] = 1;
} else {
m[temp]++;
}
}
}
for (map<string, int>::iterator it = m.begin(); it != m.end(); it++) {
if (max < it->second) {
ans = it->first;
max = it->second;
}
}
cout << ans << endl;
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
const int dayinmonth[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int num(string s) {
int res = 0;
for (int i = 0, _a = (int(s.size())); i < _a; ++i)
if (s[i] < '0' || s[i] > '9')
return -1;
else
res = res * 10 + s[i] - '0';
return res;
}
bool correct(string s) {
if (s[2] != '-' || s[5] != '-') return 0;
int day = num(s.substr(0, 2));
int month = num(s.substr(3, 2));
int year = num(s.substr(6, 4));
if (day == -1 || month == -1 || year == -1 || year < 2013 || year > 2015 ||
month < 1 || month > 12 || day < 1 || day > dayinmonth[month])
return 0;
return 1;
}
map<string, int> mm;
char s[100007];
int n;
int main() {
scanf("%s", s + 1);
n = strlen(s + 1);
string st;
for (int i = 1, _c = n - 9; i <= _c; i++) {
st = string(s + i, s + i + 10);
if (correct(st)) mm[st]++;
}
string res;
int best = 0;
for (map<string, int>::iterator it = mm.begin(); it != mm.end(); it++)
if (best < it->second) {
best = it->second;
res = it->first;
}
cout << res << endl;
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
const string f = "dd-mm-yyyy";
int month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main() {
bool ff;
string s, a;
int da, mo, ye;
map<string, int> mp;
cin >> s;
for (int i = 0; i <= s.size() - f.size(); i++) {
a = s.substr(i, f.size());
ff = true;
for (int j = 0; j < a.size(); j++) {
if (f[j] != '-' && !isdigit(a[j])) ff = false;
if (f[j] == '-' && a[j] != '-') ff = false;
}
if (!ff) continue;
if (sscanf(a.c_str(), "%2d-%2d-%4d", &da, &mo, &ye) == 3) {
if (ye >= 2013 && ye <= 2015 && mo < 13 && mo > 0 && da <= month[mo] &&
da > 0)
mp[a]++;
}
}
int maxn = 0;
for (map<string, int>::iterator it = mp.begin(); it != mp.end(); it++)
maxn = max(maxn, it->second);
for (map<string, int>::iterator it = mp.begin(); it != mp.end(); it++)
if (it->second == maxn) cout << it->first << endl;
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
string s;
map<string, int> m;
string ans;
int bns = 0;
int dd[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool type[10] = {0, 0, 1, 0, 0, 1, 0, 0, 0, 0};
bool check(string s) {
for (int i = 0; i < 10; i++) {
if (type[i]) {
if (s[i] != '-') return false;
} else {
if (!isdigit(s[i])) return false;
}
}
string ss;
ss = s.substr(5, 5);
if (ss != "-2013" && ss != "-2014" && ss != "-2015") return false;
int m = (s[3] - '0') * 10 + (s[4] - '0');
int d = (s[0] - '0') * 10 + (s[1] - '0');
if (m > 12 || m == 0) return false;
if (d > dd[m] || d == 0) return false;
return true;
}
int main() {
ios::sync_with_stdio(false);
cin >> s;
for (int i = 0; i < s.size() - 9; i++) {
string ss = s.substr(i, 10);
if (check(ss)) m[ss]++;
}
for (auto i : m) {
if (i.second > bns) {
ans = i.first;
bns = i.second;
}
}
cout << ans << endl;
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
inline int to_int(string s) {
int x = 0;
for (int i = 0; i < (int)s.size(); ++i) x *= 10, x += s[i] - '0';
return x;
}
char s[100005];
int mp[33][15][2020];
string tmp, mx;
int d, mn, y, mxx = -1, n,
m[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main(int argc, char **argv) {
scanf("%s", s);
n = strlen(s);
for (int i = 0; i < n - 9; ++i) {
if (isdigit(s[i]) && isdigit(s[i + 1]) && s[i + 2] == '-' &&
isdigit(s[i + 3]) && isdigit(s[i + 4]) && s[i + 5] == '-' &&
isdigit(s[i + 6]) && isdigit(s[i + 7]) && isdigit(s[i + 8]) &&
isdigit(s[i + 9])) {
tmp = "";
for (int j = i; j < i + 10; ++j) tmp += s[j];
d = (s[i] - '0') * 10 + (s[i + 1] - '0');
mn = (s[i + 3] - '0') * 10 + (s[i + 4] - '0');
y = (s[i + 6] - '0') * 1000 + (s[i + 7] - '0') * 100 +
(s[i + 8] - '0') * 10 + (s[i + 9] - '0');
if (y >= 2013 && y <= 2015 && mn >= 1 && mn <= 12 && d <= m[mn] &&
d >= 1) {
++mp[d][mn][y];
if (mp[d][mn][y] > mxx) {
mxx = mp[d][mn][y];
mx = tmp;
}
}
}
}
printf("%s", mx.c_str());
return 0;
}
| 8 |
CPP
|
s=input()
n=len(s)
l=list("0987654321")
cnt={}
for i in range(n-9):
t=s[i:i+10]
if t[0] in l and t[1] in l and t[2]=="-" and t[3] in l and t[4] in l and t[5]=="-" and t[6] in l and t[7] in l and t[8] in l and t[9] in l:
if 2013<=int(t[6:11])<=2015 and 1<=int(t[3:5])<=12:
if int(t[3:5]) in [1,3,5,7,8,10,12] and 1<=int(t[0:2])<=31:
if not t in cnt:
cnt[t]=1
else:
cnt[t]+=1
elif int(t[3:5]) in [4,6,9,11] and 1<=int(t[0:2])<=30:
if not t in cnt:
cnt[t]=1
else:
cnt[t]+=1
elif int(t[3:5])==2 and 1<=int(t[0:2])<=28:
if not t in cnt:
cnt[t]=1
else:
cnt[t]+=1
print(max(cnt,key=cnt.get))
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
string s;
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main() {
cin >> s;
map<string, int> mp;
int v = INT_MIN;
string ans;
int len = s.length();
for (int i = 0; i + 9 < len; i++) {
string x = s.substr(i, 10);
int d = 0, m = 0, y = 0, j = 0;
if (sscanf(((x + "*1").c_str()), "%2d-%2d-%4d*%d", &d, &m, &y, &j) != 4)
continue;
if (y < 2013 || y > 2015 || m < 1 || m > 12 || d < 1 || d > day[m - 1])
continue;
mp[x]++;
if (mp[x] > v) {
v = mp[x];
ans = x;
}
}
cout << ans;
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
map<string, int> m;
string ans;
int cnt = 0;
int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main() {
string s;
cin >> s;
for (int i = 0; i <= s.length() - 10; i++) {
if (!(isdigit(s[i]) && isdigit(s[i + 1]) && s[i + 2] == '-' &&
isdigit(s[i + 3]) && isdigit(s[i + 4]) && s[i + 5] == '-' &&
isdigit(s[i + 6]) && isdigit(s[i + 7]) && isdigit(s[i + 8]) &&
isdigit(s[i + 9])))
continue;
int d, mo, y;
sscanf(s.substr(i, 10).c_str(), "%d-%d-%d", &d, &mo, &y);
if (mo > 12 || mo < 1) continue;
if (d > days[mo] || d < 1) continue;
if (y > 2015 || y < 2013) continue;
string tmp = s.substr(i, 10);
m[tmp]++;
if (m[tmp] > cnt) {
cnt = m[tmp];
ans = tmp;
}
}
cout << ans;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
long long n, m, ans;
string str;
map<string, long long> m1;
long long solve() {
cin >> str;
n = (long long)str.size();
for (long long i = 0; i <= n - 10; ++i) {
string s = str.substr(i, 10);
vector<long long> v1;
for (long long j = 0; j <= 9; ++j) {
if (s[j] == '-') v1.push_back(j);
}
if ((long long)v1.size() == 2 && v1[0] == 2 && v1[1] == 5) {
long long f = 0;
string s1 = s.substr(0, 2);
string s2 = s.substr(3, 2);
string s3 = s.substr(6, 4);
long long a1 = stoll(s1), a2 = stoll(s2), a3 = stoll(s3);
if (a3 >= 2013 && a3 <= 2015) {
if (a2 == 1 && a1 >= 1 && a1 <= 31)
f = 1;
else if (a2 == 2 && a1 >= 1 && a1 <= 28)
f = 1;
else if (a2 == 3 && a1 >= 1 && a1 <= 31)
f = 1;
else if (a2 == 4 && a1 >= 1 && a1 <= 30)
f = 1;
else if (a2 == 5 && a1 >= 1 && a1 <= 31)
f = 1;
else if (a2 == 6 && a1 >= 1 && a1 <= 30)
f = 1;
else if (a2 == 7 && a1 >= 1 && a1 <= 31)
f = 1;
else if (a2 == 8 && a1 >= 1 && a1 <= 31)
f = 1;
else if (a2 == 9 && a1 >= 1 && a1 <= 30)
f = 1;
else if (a2 == 10 && a1 >= 1 && a1 <= 31)
f = 1;
else if (a2 == 11 && a1 >= 1 && a1 <= 30)
f = 1;
else if (a2 == 12 && a1 >= 1 && a1 <= 31)
f = 1;
}
if (f) m1[s]++;
}
}
for (auto it : m1) ans = max(ans, it.second);
for (auto it : m1) {
if (ans == it.second) {
cout << it.first;
return 0;
}
}
return 0;
}
signed main() {
ios::sync_with_stdio(0);
long long t = 1;
while (t--) solve();
return 0;
}
| 8 |
CPP
|
s = list(map(str, input().split('-')))
dic = {}
d = {1:31, 2:28, 3:31,4: 30, 5:31, 6:30, 7:31, 8:31, 9:30, 10:31, 11:30, 12:31}
for i in range(len(s)-2):
if len(s[i])>=2:
if len(s[i+1])==2 and int(s[i+1])<=12 and int(s[i+1])>=1 and int(s[i][-2]+s[i][-1])<=d[int(s[i+1])] and int(s[i][-2]+s[i][-1])>=1 and len(s[i+2])>=4 and int(s[i+2][:4])>=2013 and int(s[i+2][:4])<=2015:
st = s[i][-2]+s[i][-1]+'-'+s[i+1] + '-' + s[i+2][:4]
try:
dic[st]+=1
except:
dic[st]=1
max = 0
ind = 0
for i in dic:
if max<dic[i]:
max = dic[i]
ind = i
print(ind)
| 8 |
PYTHON3
|
from collections import defaultdict
from datetime import date
def is_correct(s):
if s.count('-') != 2 or s[2] != '-' or s[5] != '-':
return False
dd, mm, yyyy = map(int, s.split('-'))
if not (2012 < yyyy < 2016 and 0 < mm < 13):
return False
try:
date(yyyy, mm, dd)
return True
except:
return False
s, d = input(), defaultdict(int)
for i in range(len(s) - 9):
d[s[i:i+10]] += 1
for s, k in sorted(d.items(), key=lambda x: -x[1]):
if is_correct(s):
print(s)
break
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
vector<int> day, month, year;
map<pair<int, pair<int, int> >, int> mp;
int main() {
string s;
cin >> s;
int da[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
for (int i = 0; i < s.length(); i++) {
if (s[i] == '-') {
if (i < 2) continue;
if (s.length() - i <= 7) continue;
if (s[i + 3] != '-') continue;
if (s[i - 2] == '-' || s[i - 1] == '-' || s[i + 1] == '-' ||
s[i + 2] == '-' || s[i + 4] == '-' || s[i + 5] == '-' ||
s[i + 6] == '-' || s[i + 7] == '-')
continue;
int d = 10 * (s[i - 2] - '0') + (s[i - 1] - '0');
int m = 10 * (s[i + 1] - '0') + (s[i + 2] - '0');
int y = 1000 * (s[i + 4] - '0') + 100 * (s[i + 5] - '0') +
10 * (s[i + 6] - '0') + (s[i + 7] - '0');
day.push_back(d);
month.push_back(m);
year.push_back(y);
}
}
for (int i = 0; i < day.size(); i++) {
if (month[i] >= 1 && month[i] <= 12 && da[month[i]] >= day[i] &&
day[i] > 0 && year[i] > 2012 && year[i] < 2016)
mp[make_pair(day[i], make_pair(month[i], year[i]))]++;
}
map<pair<int, pair<int, int> >, int>::iterator it;
int ans = 0;
int d, m, y;
for (it = mp.begin(); it != mp.end(); ++it) {
if ((*it).second > ans) {
d = (*it).first.first;
m = (*it).first.second.first;
y = (*it).first.second.second;
ans = (*it).second;
}
}
if (d < 10) cout << "0";
cout << d << "-";
if (m < 10) cout << "0";
cout << m << "-";
cout << y;
return 0;
}
| 8 |
CPP
|
def s():
import re
pat = re.compile('\d{2}-\d{2}-\d{4}')
a = input()
se = {}
def check(x):
m = [0,31,28,31,30,31,30,31,31,30,31,30,31]
return x[2] >= 2013 and x[2] <= 2015 and x[1] >= 1 and x[1] <= 12 and x[0] >= 1 and x[0] <= m[x[1]]
for i in range(len(a)-9):
c = a[i:i+10]
if pat.match(c) and check(list(map(int,c.split('-')))):
if c in se:
se[c] += 1
else:
se[c] = 1
print(max(se.items(),key=lambda x:x[1])[0])
s()
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
const int kd[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int cnt[42][42][42];
char s[555555];
int main() {
cin >> s;
int n = strlen(s);
int mx = 0, ad = 0, am = 0, ay = 0;
memset(cnt, 0, sizeof(cnt));
for (int i = 0; i + 9 < n; i++) {
if (s[i + 2] != '-' || s[i + 5] != '-') continue;
int ok = 1;
for (int j = 0; j < 10; j++) {
if (j != 2 && j != 5 && s[i + j] == '-') ok = 0;
}
if (!ok) continue;
int dd = (s[i] - 48) * 10 + (s[i + 1] - 48);
int mm = (s[i + 3] - 48) * 10 + (s[i + 4] - 48);
if (s[i + 6] != '2' || s[i + 7] != '0' || s[i + 8] != '1') continue;
int yy = s[i + 9] - 48;
if (yy < 3 || yy > 5) continue;
if (mm < 1 || mm > 12) continue;
if (dd < 1 || dd > kd[mm]) continue;
cnt[dd][mm][yy]++;
if (cnt[dd][mm][yy] > mx) {
mx = cnt[dd][mm][yy];
ad = dd, am = mm, ay = yy;
}
}
printf("%d%d-%d%d-%d\n", ad / 10, ad % 10, am / 10, am % 10, 2010 + ay);
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
string a, b;
unordered_map<string, int> mm;
int day[15] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool check(string a) {
for (int i = 0; i < a.size(); i++) {
if (i == 2 || i == 5) {
if (a[i] != '-') {
return false;
}
} else {
if (a[i] == '-') {
return false;
}
}
}
int nn = 10 * (a[3] - '0') + a[4] - '0';
if (day[nn] < 10 * (a[0] - '0') + a[1] - '0' ||
10 * (a[0] - '0') + a[1] - '0' == 0 || nn == 0) {
return false;
}
nn =
1000 * (a[6] - '0') + 100 * (a[7] - '0') + 10 * (a[8] - '0') + a[9] - '0';
if (nn < 2013 || nn > 2015) {
return false;
}
return true;
}
string ans;
int cc = 0;
int main() {
cin >> a;
for (int i = 0; i <= a.size() - 10; i++) {
b = a.substr(i, 10);
if (check(b)) {
mm[b]++;
if (mm[b] > cc) {
cc = mm[b];
ans = b;
}
}
b.clear();
}
cout << ans;
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
int ji[4][15][35];
int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool judge(int day, int month, int year) {
if ((year >= 2013 && year <= 2015) == 0) return false;
if ((month >= 1 && month <= 12) == 0) return false;
if ((day > 0 && day <= mon[month]) == 0) return false;
return true;
}
inline void solve(string s) {
int i = 0, day, month, year;
day = month = year = 0;
while (s[i] != '-' && i != s.size()) {
day = day * 10 + s[i] - '0';
i++;
}
if (i != 2) return;
i++;
while (s[i] != '-' && i != s.size()) {
month = month * 10 + s[i] - '0';
i++;
}
if (i != 5) return;
i++;
while (s[i] != '-' && i != s.size()) {
year = year * 10 + s[i] - '0';
i++;
}
if (i != 10) return;
if (!judge(day, month, year)) return;
ji[year - 2013][month][day]++;
}
string s;
int main() {
getline(cin, s);
for (int i = 0; i < s.size() - 9; i++) {
string t = s.substr(i, 10);
solve(t);
}
int day, month, year, pnt = 0;
day = month = year = 0;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 15; j++) {
for (int k = 0; k < 35; k++) {
if (pnt < ji[i][j][k]) {
year = i + 2013;
month = j;
day = k;
pnt = ji[i][j][k];
}
}
}
}
if (day < 10) cout << 0;
printf("%d-", day);
if (month < 10) cout << 0;
printf("%d-%d\n", month, year);
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
const double PI = acos(-1), EPS = 1e-7;
const int OO = 0x3f3f3f3f, N = 1e5 + 5, mod = 1e9 + 7;
using namespace std;
long long gcd(long long x, long long y) { return (!y) ? x : gcd(y, x % y); }
long long lcm(long long x, long long y) { return ((x / gcd(x, y)) * y); }
void file() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
bool ok(string s) {
int y = s[6] - '0';
y *= 10;
y += (s[7] - '0');
y *= 10;
y += (s[8] - '0');
y *= 10;
y += (s[9] - '0');
if (!(y >= 2013 && y <= 2015)) return 0;
int m = s[3] - '0';
m *= 10;
m += s[4] - '0';
int d = s[0] - '0';
d *= 10;
d += s[1] - '0';
if (!(m >= 1 && m <= 12)) return 0;
if (!(d >= 1 && d <= 31)) return 0;
if (d > 28 && m == 2) return 0;
if (d == 31 &&
(m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12))
return 1;
else if (d == 31)
return 0;
return 1;
}
int main() {
file();
string s;
cin >> s;
string d = "13-12-2013";
map<string, int> mp;
for (int i = 0; i <= (int)s.size() - (int)d.size(); i++) {
string cur = s.substr(i, (int)d.size());
int cnt = 0;
for (int j = 0; j < (int)cur.size(); j++)
if (cur[j] == '-') cnt++;
if (cnt != 2 || cur[2] != '-' || cur[5] != '-') continue;
if (ok(cur)) {
mp[cur]++;
}
}
int mx = 0;
string ans;
for (auto t : mp) {
if (t.second > mx) {
mx = t.second;
ans = t.first;
}
}
cout << ans;
}
| 8 |
CPP
|
from re import findall
from calendar import monthrange
from collections import defaultdict
S = input()
bag = defaultdict(int)
for s in findall('(?=(\d\d-\d\d-201[3-5]))', S): # (?=...) implies that overlap is allowed
d, m, y = map(int, s.split('-'))
if 1 <= m <= 12 and 1 <= d <= monthrange(y, m)[1]:
bag[s] += 1
print(max(bag, key = bag.get))
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
double const eps = 1e-6;
const int inf = 0x3fffffff;
const int size = 100000 + 5;
int sz;
map<string, int> cnt;
int day[13] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool valid(int y, int m, int d) {
if (y < 2013 || y > 2015) return false;
if (m < 1 || m > 12) return false;
if (d < 1 || d > day[m]) return false;
return true;
}
int mx;
string ans;
void take(string str, int k) {
for (int i = 0; i < (int)str.size(); i++)
if (str[i] == '-' && i != 2 && i != 5) return;
const char* s = str.c_str();
int y, m, d;
sscanf(s, "%d-%d-%d", &d, &m, &y);
if (valid(y, m, d)) {
if (cnt.find(str) == cnt.end())
cnt[str] = 1;
else
cnt[str]++;
if (cnt[str] > mx) {
mx = cnt[str];
ans = str;
}
}
}
int main() {
string str;
cin >> str;
sz = str.size();
for (int i = 0; i <= sz - 10; i++)
if (str[i + 2] == '-') {
take(str.substr(i, 10), i);
}
cout << ans << endl;
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
struct Date {
int d, m, y;
};
bool operator<(Date a, Date b) {
return make_pair(make_pair(a.d, a.m), a.y) <
make_pair(make_pair(b.d, b.m), b.y);
}
int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
string s;
bool cor_date(int i) {
for (int j = 0; j < 10; j++) {
if ((j == 2) || (j == 5)) {
if (s[i + j] != '-') return 0;
} else {
if (s[i + j] == '-') return 0;
}
}
int y = (((s[i + 6] - '0') * 10 + (s[i + 7] - '0')) * 10 + (s[i + 8] - '0')) *
10 +
(s[i + 9] - '0');
int m = (s[i + 3] - '0') * 10 + (s[i + 4] - '0');
int d = (s[i + 0] - '0') * 10 + (s[i + 1] - '0');
if ((y <= 2015) && (y >= 2013) && (m <= 12) && (m >= 1) && (d >= 1) &&
(d <= days[m - 1])) {
return 1;
}
return 0;
}
Date get_date(int i) {
int y = (((s[i + 6] - '0') * 10 + (s[i + 7] - '0')) * 10 + (s[i + 8] - '0')) *
10 +
(s[i + 9] - '0');
int m = (s[i + 3] - '0') * 10 + (s[i + 4] - '0');
int d = (s[i + 0] - '0') * 10 + (s[i + 1] - '0');
Date D;
D.y = y;
D.m = m;
D.d = d;
return D;
}
string Dat(Date d) {
string s;
s += d.d / 10 + '0';
s += d.d % 10 + '0';
s += '-';
s += d.m / 10 + '0';
s += d.m % 10 + '0';
s += '-';
s += d.y / 1000 + '0';
d.y %= 1000;
s += d.y / 100 + '0';
d.y %= 100;
s += d.y / 10 + '0';
d.y %= 10;
s += d.y + '0';
return s;
}
map<Date, int> ma;
int main() {
cin >> s;
for (int i = 0; i <= (int)s.size() - 10; i++) {
if (cor_date(i)) {
ma[get_date(i)]++;
}
}
int mx = 0;
Date D;
bool flag = 0;
for (map<Date, int>::iterator it = ma.begin(); it != ma.end(); it++) {
if (it->second > mx) {
mx = it->second;
D = it->first;
flag = 0;
} else {
if (it->second == mx) {
flag = 1;
}
}
}
cout << Dat(D) << endl;
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
const long long OO = 1e8;
string CF[] = {"NO", "YES"};
bool isDigit(string S) {
for (int i = 0; i < (int)((int)((S).size())); ++i) {
if (S[i] < '0' || S[i] > '9') return false;
}
return true;
}
bool Valid(string M) {
if (M == "01" || M == "03" || M == "05" || M == "07" || M == "08" ||
M == "10" || M == "12")
return true;
return false;
}
bool CS(char S) {
if (S == '-') return true;
return false;
}
bool Valid2(string M) {
if (M == "04" || M == "06" || M == "09" || M == "11") return true;
return false;
}
int main() {
ios_base ::sync_with_stdio(0);
;
string Str;
cin >> Str;
map<string, long long> M;
for (int i = 0; i < (int)((int)((Str).size()) - 9); ++i) {
string Sub = Str.substr(i, 10);
string D1 = Sub.substr(0, 2);
string M1 = Sub.substr(3, 2);
string Y1 = Sub.substr(6);
if (CS(Sub[2]) && CS(Sub[5])) {
if (isDigit(Y1) && Y1 >= "2013" && Y1 <= "2015") {
if (Valid(M1) && isDigit(D1) && D1 >= "01" && D1 <= "31")
M[Sub]++;
else if (Valid2(M1) && isDigit(D1) && D1 >= "01" && D1 <= "30")
M[Sub]++;
else if (M1 == "02" && isDigit(D1) && D1 >= "01" && D1 <= "28")
M[Sub]++;
}
}
}
vector<pair<string, int> > A;
long long Mx = 0;
copy((M).begin(), (M).end(), back_inserter<vector<pair<string, int> > >(A));
for (int i = 0; i < (int)((int)((A).size())); ++i) {
if (Mx < A[i].second) Mx = A[i].second, Str = A[i].first;
}
if (Mx == A[0].second)
cout << A[0].first << endl;
else
cout << Str << endl;
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
int Day[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int maxx = -1;
int main() {
string s, ans;
cin >> s;
map<string, int> mp;
for (int i = 0; i < (int)s.size() - 9; i++) {
string t = s.substr(i, 10);
int year =
(t[9] - 48) + (t[8] - 48) * 10 + (t[7] - 48) * 100 + (t[6] - 48) * 1000;
int month = (t[4] - 48) + (t[3] - 48) * 10;
int day = (t[1] - 48) + (t[0] - 48) * 10;
if (year > 2015 || year < 2013 || month > 12 || month < 1 ||
day > Day[month] || day < 1 || count(t.begin(), t.end(), '-') != 2) {
continue;
}
mp[t]++;
if (mp[t] > maxx) {
maxx = mp[t];
ans = t;
}
}
cout << ans << endl;
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
int n;
long long table[40][40];
long long solve(int nodes, int h) {
if (nodes == 0) {
return 1LL;
}
if (h == 0) {
return 0;
}
long long &ret = table[nodes][h];
if (ret != -1) return ret;
ret = 0;
for (int i = 0; i < nodes; ++i) {
ret += solve(i, max(h - 1, 0)) * solve(nodes - i - 1, max(h - 1, 0));
}
return ret;
}
string days[] = {"01", "02", "03", "04", "05", "06", "07", "08",
"09", "10", "11", "12", "13", "14", "15", "16",
"17", "18", "19", "20", "21", "22", "23", "24",
"25", "26", "27", "28", "29", "30", "31"};
string months[] = {"01", "02", "03", "04", "05", "06",
"07", "08", "09", "10", "11", "12"};
int lim[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int fail[100];
char t[100010], p[100];
inline void buildFail() {
int m = strlen(p);
int j = fail[0] = -1;
for (int i = 1; i <= m; ++i) {
while (j >= 0 && p[j] != p[i - 1]) j = fail[j];
fail[i] = ++j;
}
}
int match() {
int n = strlen(t), m = strlen(p);
int count = 0;
for (int i = 0, k = 0; i < n; ++i) {
while (k >= 0 && p[k] != t[i]) k = fail[k];
if (++k >= m) {
++count;
k = fail[k];
}
}
return count;
}
int main() {
string in;
cin >> t;
int maxo = 0, koko;
string ans;
string tmpo;
for (int i = 0; i < 12; ++i) {
for (int j = 0; j < lim[i]; ++j) {
tmpo = days[j] + "-" + months[i] + "-" + "2013";
strcpy(p, tmpo.c_str());
buildFail();
koko = match();
if (koko > maxo) {
maxo = koko;
ans = tmpo;
}
tmpo = days[j] + "-" + months[i] + "-" + "2014";
strcpy(p, tmpo.c_str());
buildFail();
koko = match();
if (koko > maxo) {
maxo = koko;
ans = tmpo;
}
tmpo = days[j] + "-" + months[i] + "-" + "2015";
strcpy(p, tmpo.c_str());
buildFail();
koko = match();
if (koko > maxo) {
maxo = koko;
ans = tmpo;
}
}
}
cout << ans << endl;
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const double EPS = 1e-9, INF = 1e12;
string in;
int day(int y, int m) {
int d[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
return d[m] + (y % 4 == 0);
}
int main() {
cin >> in;
map<string, int> cnt;
for (int i = 0; i < (int)in.size() - 9; i++) {
if (isdigit(in[i]) && isdigit(in[i + 1]) && isdigit(in[i + 3]) &&
isdigit(in[i + 4]) && isdigit(in[i + 6]) && isdigit(in[i + 7]) &&
isdigit(in[i + 8]) && isdigit(in[i + 9]) && in[i + 2] == '-' &&
in[i + 5] == '-') {
int y = atoi(in.substr(i + 6, 4).c_str());
int m = atoi(in.substr(i + 3, 2).c_str());
int d = atoi(in.substr(i, 2).c_str());
if (2013 <= y && y <= 2015 && 1 <= m && m <= 12 && 1 <= d &&
d <= day(y, m))
cnt[in.substr(i, 10)]++;
}
}
int mx = 0;
for (__typeof(cnt.begin()) i = cnt.begin(); i != cnt.end(); i++)
mx = max(mx, i->second);
for (__typeof(cnt.begin()) i = cnt.begin(); i != cnt.end(); i++)
if (i->second == mx) cout << i->first << endl;
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
vector<int> mods = {1000000007, 1000000009, 998244353};
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const int maxn = 200005;
const int mod = mods[0];
const int day[15] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
void task() {
string s;
cin >> s;
std::map<string, int> u;
string ans = "";
int d, m, y, r, mx = 0;
for (int i = 0; i + 10 <= s.size(); i++) {
string x = s.substr(i, 10);
if (sscanf((x + "*1").c_str(), "%2d-%2d-%4d*%d", &d, &m, &y, &r) == 4) {
if (m > 0 && m <= 12 && y >= 2013 && y <= 2015 && d > 0 && d <= day[m]) {
u[x]++;
if (u[x] > mx) {
mx = u[x];
ans = x;
}
}
}
}
cout << ans << "\n";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int T = 1;
for (int __ = 1; __ <= T; __++) {
task();
}
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) {
if (y == 0)
return x;
else
return gcd(y, x % y);
}
int main() {
long long mon[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
string s, ans;
cin >> s;
long long ma = 0;
for (long long i = 2013; i < 2016; i++) {
for (long long j = 1; j < 13; j++) {
for (long long k = 1; k <= mon[j - 1]; k++) {
long long c = 0;
string t;
if (k < 10) t = "0";
t = t + to_string(k) + "-";
if (j < 10) t = t + "0";
t = t + to_string(j) + "-";
t = t + to_string(i);
size_t f = 0;
while ((f = s.find(t, f)) != -1) {
c++;
f++;
}
if (c > ma) {
ma = c;
ans = t;
}
}
}
}
cout << ans;
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool check(string in) {
if (in[2] != '-' || in[5] != '-') return false;
int d = 0, m = 0, y = 0;
for (int ctr1 = 0; ctr1 < 10; ctr1++) {
if (ctr1 == 2) {
d = y;
y = 0;
continue;
}
if (ctr1 == 5) {
m = y;
y = 0;
continue;
}
if (!isdigit(in[ctr1])) return false;
y = y * 10 + in[ctr1] - '0';
}
if (y < 2013 || y > 2015) return false;
if (m <= 0 || m > 12) return false;
if (d <= 0 || d > days[m - 1]) return false;
return true;
}
int main() {
string prop;
cin >> prop;
map<string, int> mp;
for (int ctr1 = 0; ctr1 < prop.size() - 9; ctr1++) {
string cur = prop.substr(ctr1, 10);
if (check(cur)) {
mp[cur]++;
}
}
string rez;
int ma = 0;
for (auto it = mp.begin(); it != mp.end(); it++) {
if (it->second > ma) {
ma = it->second;
rez = it->first;
}
}
cout << rez;
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[13] = {0};
a[1] = 31;
a[2] = 28;
a[3] = 31;
a[4] = 30;
a[5] = 31;
a[6] = 30;
a[7] = 31;
a[8] = 31;
a[9] = 30;
a[10] = 31;
a[11] = 30;
a[12] = 31;
int b[3][13][40];
for (int i = 0; i < 3; i++) {
for (int j = 0; j <= 12; j++) {
for (int k = 0; k < 40; k++) {
b[i][j][k] = 0;
}
}
}
string s;
cin >> s;
int n = s.size();
for (int i = 0; i <= n - 10; i++) {
if ((s[i] != '-') && (s[i + 1] != '-') && (s[i + 2] == '-') &&
(s[i + 3] != '-') && (s[i + 4] != '-') && (s[i + 5] == '-') &&
(s[i + 6] != '-') && (s[i + 7] != '-') && (s[i + 8] != '-') &&
(s[i + 9] != '-')) {
int d, m, y;
d = ((((int)s[i]) - 48) * 10) + (((int)s[i + 1]) - 48);
m = ((((int)s[i + 3]) - 48) * 10) + (((int)s[i + 4]) - 48);
y = ((((int)s[i + 6]) - 48) * 1000) + ((((int)s[i + 7]) - 48) * 100) +
((((int)s[i + 8]) - 48) * 10) + (((int)s[i + 9]) - 48);
if ((y <= 2015) && (y >= 2013)) {
if ((m > 0) && (m <= 12)) {
if ((d > 0) && (d <= a[m])) {
b[y - 2013][m][d] += 1;
}
}
}
}
}
int d1, m1, y1;
int maxx = 0;
for (int i = 0; i < 3; i++) {
for (int j = 0; j <= 12; j++) {
for (int k = 0; k < 40; k++) {
if (b[i][j][k] > maxx) {
maxx = b[i][j][k];
y1 = i + 2013;
m1 = j;
d1 = k;
}
}
}
}
if ((d1 > 9) && (m1 > 9)) {
cout << d1 << "-" << m1 << "-" << y1 << endl;
}
if ((d1 > 9) && (m1 < 10)) {
cout << d1 << "-" << 0 << m1 << "-" << y1 << endl;
}
if ((d1 < 10) && (m1 > 9)) {
cout << d1 << "-" << m1 << "-" << y1 << endl;
}
if ((d1 < 10) && (m1 < 10)) {
cout << 0 << d1 << "-" << 0 << m1 << "-" << y1 << endl;
}
}
| 8 |
CPP
|
import re
from collections import defaultdict
s = input()
x = re.findall("(?=(\d\d-\d\d-\d\d\d\d))", s)
month_to_day = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
ans = ""
def val():
return 0
date_count = defaultdict(val)
max_count = 0
for date in x:
d, m, y = [int(x) for x in date.split('-')]
if(2013 <= y <= 2015 and 1 <= d <= 31 and 1 <= m <= 12 and 0 < d <= month_to_day[m]):
date_count[date] += 1
if date in date_count and date_count[date] > max_count:
max_count = date_count[date]
ans = date
print(ans)
| 8 |
PYTHON3
|
s = input()
x = s.split('-')
cnt = {}
days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
for i in range(2, len(x)):
day = x[i - 2][-2:]
month = x[i - 1]
year = x[i][:4]
if len(year) == 4 and 2013 <= int(year) <= 2015 and len(day) == 2 and len(month) == 2:
d = int(day)
m = int(month)
if 1 <= m <= 12 and 1 <= d <= days[m - 1]:
key = '%s-%s-%s' % (day, month, year)
cnt[key] = cnt.get(key, 0) + 1
m = 0
for key, val in cnt.items():
if val > m:
m = val
res = key
print(res)
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
vector<string> A;
for (int I = 0; I < s.length() - 9; I += 1) {
string sub = s.substr(I, 10);
bool ValidDM = false;
int Day = 0;
if (sub[0] == '0') {
Day = sub[1] - '0';
} else
Day = (sub[0] - '0') * 10 + (sub[1] - '0');
int Mon = 0;
if (sub[3] == '0') {
Mon = sub[4] - '0';
} else
Mon = (sub[3] - '0') * 10 + (sub[4] - '0');
if (sub[0] >= '0' && sub[0] <= '9' && sub[1] >= '0' && sub[1] <= '9' &&
sub[3] >= '0' && sub[3] <= '9' && sub[4] >= '0' && sub[4] <= '9') {
if (Mon == 1)
if (Day <= 31) ValidDM = true;
if (Mon == 2)
if (Day <= 28) ValidDM = true;
if (Mon == 3)
if (Day <= 31) ValidDM = true;
if (Mon == 4)
if (Day <= 30) ValidDM = true;
if (Mon == 5)
if (Day <= 31) ValidDM = true;
if (Mon == 6)
if (Day <= 30) ValidDM = true;
if (Mon == 7)
if (Day <= 31) ValidDM = true;
if (Mon == 8)
if (Day <= 31) ValidDM = true;
if (Mon == 9)
if (Day <= 30) ValidDM = true;
if (Mon == 10)
if (Day <= 31) ValidDM = true;
if (Mon == 11)
if (Day <= 30) ValidDM = true;
if (Mon == 12)
if (Day <= 31) ValidDM = true;
} else
continue;
if (Day == 0) continue;
bool ValidY = false;
if (sub[6] == '2' && sub[7] == '0' && sub[8] == '1' &&
(sub[9] == '3' || sub[9] == '4' || sub[9] == '5'))
ValidY = true;
bool ValidOther = false;
if (sub[2] == '-' && sub[5] == '-') ValidOther = true;
if (ValidOther && ValidY && ValidDM) {
A.push_back(sub);
continue;
}
}
int maxT = 0;
int res;
for (int I = 0; I < A.size(); I += 1) {
int occ = 0;
for (int T = 0; T < A.size(); T += 1) {
if (A[I] == A[T]) occ += 1;
}
if (occ > maxT) {
maxT = occ;
res = I;
}
}
cout << A[res];
}
| 8 |
CPP
|
def checkKey(dict, key):
if key in dict:
return True
return False
# def helper(s):
# l=len(s)
# if (l==1):
# l=[]
# l.append(s)
# return l
# ch=s[0]
# recresult=helper(s[1:])
# myresult=[]
# myresult.append(ch)
# for st in recresult:
# myresult.append(st)
# ts=ch+st
# myresult.append(ts)
# return myresult
# mod=1000000000+7
# def helper(s,n,open,close,i):
# if(i==2*n):
# for i in s:
# print(i,end='')
# print()
# return
# if(open<n):
# s[i]='('
# helper(s,n,open+1,close,i+1)
# if(close<open):
# s[i]=')'
# helper(s,n,open,close+1,i+1)
# def helper(arr,i,n):
# if(i==n-1):
# recresult=[arr[i]]
# return recresult
# digit=arr[i]
# recresult=helper(arr,i+1,n)
# myresult=[]
# for i in recresult:
# myresult.append(i)
# myresult.append(i+digit);
# myresult.append(digit)
# return myresult
# import copy
# n=int(input())
# arr=list(map(int,input().split()))
# ans=[]
# def helper(arr,i,n):
# if(i==n-1):
# # for a in arr:
# # print(a,end=" ")
# # print()
# l=copy.deepcopy(arr)
# ans.append(l)
# return
# for j in range(i,n):
# if(i!=j):
# if(arr[i]==arr[j]):
# continue
# else:
# arr[i],arr[j]=arr[j],arr[i]
# helper(arr,i+1,n)
# arr[j],arr[i]=arr[i],arr[j]
# else:
# arr[i],arr[j]=arr[j],arr[i]
# helper(arr,i+1,n)
# def helper(sol,n,m):
# for i in range(n+1):
# for j in range(m+1):
# print(sol[i][j],end=" ")
# print()
# def rat_in_a_maze(maze,sol,i,j,n,m):
# if(i==n and j==m):
# sol[i][j]=1
# helper(sol,n,m)
# exit()
# if(i>n or j>m):
# return False
# if(maze[i][j]=='X'):
# return False
# maze[i][j]='X'
# sol[i][j]=1
# if(rat_in_a_maze(maze,sol,i,j+1,n,m)):
# return True
# elif(rat_in_a_maze(maze,sol,i+1,j,n,m)):
# return True
# sol[i][j]=0
# return False
def isdate(s):
if(s[2]=='-' and s[5]=='-'):
if(s[0:2].isdigit() and s[3:5].isdigit() and s[6:].isdigit()):
return True
return False
def valid_date(s,months):
day=int(s[0:2])
month=int(s[3:5])
year=int(s[6:])
if(2013<=year<=2015 and 1<=month<=12 and 1<=day<=months[month]):
return True
return False
s=input()
l=len(s)
d={}
month=[0,31,28,31,30,31,30,31,31,30,31,30,31]
for i in range(0,l-10+1):
date=s[i:i+10]
if(isdate(date) and valid_date(date,month)):
if date in d:
d[date]+=1
else:
d[date]=1
m=0
ans=""
for i in d:
if(d[i]>m):
m=d[i]
ans=i
print(ans)
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
char str[123456];
char it[123];
char day[13][5] = {"31", "28", "31", "30", "31", "30",
"31", "31", "30", "31", "30", "31"};
map<string, int> m;
map<string, int>::iterator ut;
int main() {
scanf("%s", str);
int len = strlen(str);
m.clear();
for (int i = 0; i < len - 3; i++) {
if (str[i] == '-' && str[i + 3] == '-' && str[i + 4] == '2' &&
str[i + 5] == '0' && str[i + 6] == '1') {
int flag = 0;
for (int j = 0; j < 10; j++) {
it[j] = str[i + j - 2];
}
it[10] = '\0';
if (it[9] < '3' || it[9] > '5') flag = 1;
if (it[3] < '0' || it[3] > '9' || it[3] > '1') flag = 1;
if (it[3] == '0') {
if (it[4] < '0' || it[4] > '9' || it[4] == '0') flag = 1;
}
if (it[3] == '1') {
if (it[4] < '0' || it[4] > '9' || it[4] > '2') flag = 1;
}
if (it[0] < '0' || it[0] > '9') flag = 1;
if (it[0] == '0') {
if (it[1] <= '0' || it[1] > '9') flag = 1;
} else {
if (it[1] < '0' || it[1] > '9') flag = 1;
}
int u = (it[3] - '0') * 10 + (it[4] - '0');
char t[3];
t[0] = it[0], t[1] = it[1];
t[2] = '\0';
if (strcmp(t, day[u - 1]) > 0) flag = 1;
if (!flag) {
string t = "";
for (int j = 0; j < 10; j++) t += it[j];
m[t]++;
}
}
}
string ans;
int u = -1;
for (ut = m.begin(); ut != m.end(); ut++) {
if (ut->second > u) {
u = ut->second;
ans = ut->first;
}
}
cout << ans << endl;
return 0;
}
| 8 |
CPP
|
p=input()
data={}
days=[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
for i in range(len(p)-9):
if p[i+2] == p[i+5] == "-" and (p[i+6:i+10]).isdecimal() \
and 2013 <= int(p[i+6:i+10]) <= 2015 and p[3+i:5+i].isdecimal() and \
1 <= int(p[i+3:i+5]) <= 12 and p[i:2+i].isdecimal() and 0 < int(p[i:2+i]) <= days[int(p[i+3:i+5])-1] :
if p[i:i+10] in data:
data[p[i:i+10]]+=1
else:
data[p[i:i+10]]=1
max_item=None
maximum=0
for i in data.keys():
if data[i] > maximum:
maximum = data[i]
max_item=i
print(max_item)
| 8 |
PYTHON3
|
from re import findall
from calendar import monthrange
from collections import defaultdict
n=input()
dic=defaultdict(int)
for i in findall('(?=(\d\d-\d\d-201[3-5]))',n):
d,m,y=map(int,i.split('-'))
if 1<=m<=12 and 1<=d<=monthrange(y,m)[1]:
dic[i]+=1
print(max(dic,key=dic.get))
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
map<string, int> mm;
const int months[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool isnum(char a) {
if (a < '0' || a > '9') return false;
return true;
}
bool judge(string a) {
if (!(isnum(a[0]) && isnum(a[1]) && isnum(a[3]) && isnum(a[4]) &&
isnum(a[6]) && isnum(a[7]) && isnum(a[8]) && isnum(a[9])))
return false;
if (a[2] != '-' || a[5] != '-') return false;
int year = (a[6] - '0') * 1000 + (a[7] - '0') * 100 + (a[8] - '0') * 10 +
(a[9] - '0');
int month = (a[3] - '0') * 10 + (a[4] - '0');
int day = (a[0] - '0') * 10 + (a[1] - '0');
if (year < 2013 || year > 2015) return false;
if (month < 1 || month > 12) return false;
if (day < 1 || day > months[month]) return false;
return true;
}
int main() {
string str, s;
while (cin >> str) {
mm.clear();
s = "21-12-2013";
for (int i = 0; i <= str.size() - 10; i++) {
for (int j = 0; j != 10; j++) {
s[j] = str[i + j];
}
mm[s]++;
}
map<string, int>::iterator it;
int mmax = -1;
for (it = mm.begin(); it != mm.end(); ++it) {
if (mmax < (it->second)) {
if (judge(it->first)) {
s = it->first;
mmax = it->second;
}
}
}
cout << s << endl;
}
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
int main() {
string str, a;
while (cin >> str) {
int k = 0, t = 0;
int sh[100001], maxx = 0, l;
string ss[100001];
memset(sh, 0, sizeof(sh));
for (int i = 0; i < str.length(); i++) {
int flag = 0;
a = str.substr(i, 10);
if (mp[a] == 0) {
mp[a] = ++t;
ss[t] = a;
}
int u = mp[a];
sh[u]++;
int mm = 0, dd = 0, yy = 0;
for (int j = 0; j < a.length(); j++) {
if (j == 2 || j == 5) {
if (a[j] != '-') flag = 1;
} else if (a[j] < '0' || a[j] > '9')
flag = 1;
}
dd = (a[0] - '0') * 10 + a[1] - '0';
mm = (a[3] - '0') * 10 + a[4] - '0';
yy = (a[6] - '0') * 1000 + (a[7] - '0') * 100 + (a[8] - '0') * 10 + a[9] -
'0';
if (mm < 1 || mm > 12) flag = 1;
if (yy < 2013 || yy > 2015) flag = 1;
if (mm == 1 || mm == 3 || mm == 5 || mm == 7 || mm == 8 || mm == 10 ||
mm == 12) {
if (dd <= 0 || dd > 31) flag = 1;
} else if (mm == 2) {
if (dd <= 0 || dd > 28) flag = 1;
} else {
if (dd <= 0 || dd > 30) flag = 1;
}
if (sh[u] > maxx && !flag) {
maxx = sh[u];
l = u;
}
}
cout << ss[l] << endl;
}
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
void prv(vector<int> v) {
int n = v.size();
for (int i = 0; i < n; i++) cout << v[i] << " ";
}
void swap(long long int &a, long long int &b) {
int tm = a;
a = b;
b = tm;
}
bool comp(const pair<int, int> &p1, const pair<int, int> &p2) {
if (p1.first > p2.first)
return 1;
else
return 0;
}
const int N = 3e5 + 5;
void findPrefix(string pattern, int m, int prefArray[]) {
int length = 0;
prefArray[0] = 0;
for (int i = 1; i < m; i++) {
if (pattern[i] == pattern[length]) {
length++;
prefArray[i] = length;
} else {
if (length != 0) {
length = prefArray[length - 1];
i--;
} else
prefArray[i] = 0;
}
}
}
int kmpPattSearch(string mainString, string pattern) {
int n, m, i = 0, j = 0, fr = 0;
n = mainString.size();
m = pattern.size();
int prefixArray[m];
findPrefix(pattern, m, prefixArray);
while (i < n) {
if (mainString[i] == pattern[j]) {
i++;
j++;
}
if (j == m) {
fr++;
j = prefixArray[j - 1];
} else if (i < n && pattern[j] != mainString[i]) {
if (j != 0)
j = prefixArray[j - 1];
else
i++;
}
}
return fr;
}
string crts(int d, int m, int y) {
string t;
t.clear();
while (y != 0) {
t.push_back(y % 10 + '0');
y = y / 10;
}
t.push_back('-');
while (m != 0) {
t.push_back(m % 10 + '0');
m = m / 10;
}
if (t.size() == 6) t.push_back('0');
t.push_back('-');
while (d != 0) {
t.push_back(d % 10 + '0');
d = d / 10;
}
if (t.size() == 9) t.push_back('0');
reverse((t).begin(), (t).end());
return t;
}
void solve() {
string s, ans;
cin >> s;
int mx = 0;
for (int i = 2013; i < 2016; ++i) {
for (int j = 1; j <= 12; j++) {
int k;
if (j == 2)
k = 28;
else if (j == 1 || j == 3 || j == 5 || j == 7 || j == 8 || j == 10 ||
j == 12)
k = 31;
else
k = 30;
for (int l = 1; l <= k; l++) {
string t;
int frq;
t = crts(l, j, i);
frq = kmpPattSearch(s, t);
if (frq > mx) {
mx = frq;
ans = t;
}
}
}
}
cout << ans;
}
signed int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
while (t--) {
solve();
cout << "\n";
}
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
string s;
map<string, int> a;
int num_days[20] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main() {
int ma = -10;
cin >> s;
string pointer;
for (int i = 0; i < s.size(); ++i) {
string f;
f.clear();
if (isdigit(s[i]) && isdigit(s[i + 1]) && s[i + 2] == '-' &&
isdigit(s[i + 3]) && isdigit(s[i + 4]) && s[i + 5] == '-' &&
isdigit(s[i + 6]) && isdigit(s[i + 7]) && isdigit(s[i + 8]) &&
isdigit(s[i + 9])) {
int data = ((s[i] - 48) * 10) + (s[i + 1] - 48);
int month = ((s[i + 3] - 48) * 10) + (s[i + 4] - 48);
int year = ((s[i + 6] - 48) * 1000) + ((s[i + 7] - 48) * 100) +
((s[i + 8] - 48) * 10) + (s[i + 9] - 48);
if (data >= 1 && data <= num_days[month] && year >= 2013 &&
year <= 2015) {
for (int j = i; j < i + 10; ++j) f.push_back(s[j]);
}
}
if (f != "") {
a[f]++;
if (a[f] > ma) {
ma = a[f];
pointer = f;
}
}
}
cout << pointer;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
int Days(int Month) {
if (Month == 2) return 28;
if (Month == 4 || Month == 6 || Month == 9 || Month == 11) return 30;
return 31;
}
int Calc(string S) {
if (S[2] != '-' || S[5] != '-') return -1;
for (int i = 0; i < 10; i++) {
if (i == 2 || i == 5) continue;
if (S[i] < '0' || S[i] > '9') return -1;
}
int Day = (S[0] - 48) * 10 + (S[1] - 48);
int Month = (S[3] - 48) * 10 + (S[4] - 48);
int Year =
(S[6] - 48) * 1000 + (S[7] - 48) * 100 + (S[8] - 48) * 10 + (S[9] - 48);
if (Year < 2013 || Year > 2015) return -1;
if (Month < 1 || Month > 12) return -1;
if (Day < 1 || Day > Days(Month)) return -1;
return (Year - 2013) * 10000 + Month * 100 + Day;
}
void Output(int X) {
putchar(X / 10 + 48);
putchar(X % 10 + 48);
}
int main() {
string S;
cin >> S;
static int Count[30000];
memset(Count, 0, sizeof(Count));
for (int i = 0; i + 10 <= S.size(); i++) {
string T = "";
for (int j = 0; j < 10; j++) T += S[i + j];
int Temp = Calc(T);
if (Temp != -1) Count[Temp]++;
}
int Ans = 0;
for (int i = 1; i < 30000; i++)
if (Count[i] > Count[Ans]) Ans = i;
Output(Ans % 100);
putchar('-');
Output(Ans / 100 % 100);
putchar('-');
printf("%d\n", Ans / 10000 + 2013);
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e9;
map<string, int> my_map;
int m_days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main() {
string inp;
cin >> inp;
for (int i = 0; i < inp.size(); i++) {
string buff = inp.substr(i, 10);
bool flag = false;
if (buff[2] != '-' || buff[5] != '-') flag = true;
for (int j = 0; j < 10; j++)
if (j != 2 && j != 5 && buff[j] == '-') flag = true;
if (flag) continue;
int date = (buff[0] - '0') * 10 + (buff[1] - '0');
int month = (buff[3] - '0') * 10 + (buff[4] - '0');
int year = (buff[6] - '0') * 1000 + (buff[7] - '0') * 100 +
(buff[8] - '0') * 10 + (buff[9] - '0');
if (year >= 2013 && year <= 2015)
if (month >= 1 && month <= 12)
if (date && date <= m_days[month - 1]) my_map[buff]++;
}
map<string, int>::iterator mx = my_map.begin();
for (map<string, int>::iterator i = mx; i != my_map.end(); i++)
if (i->second > mx->second) mx = i;
cout << mx->first << endl;
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
long long int biexp(long long int a, long long int b) {
long long int res = 1;
while (b) {
if (b % 2) res = res * a;
a = a * a;
b = b / 2;
}
return res;
}
int main() {
int t = 1;
while (t--) {
string s;
cin >> s;
string r;
long long int x = 0;
string s2;
map<string, long long int> v;
for (long long int i = 0; i <= s.length() - 10; i++) {
r = s.substr(i, 10);
long long int d = (r[0] - '0') * 10 + (r[1] - '0');
long long int m = (r[3] - '0') * 10 + (r[4] - '0');
if (r[0] != '-' and r[1] != '-' and r[2] == '-' and r[3] != '-' and
r[4] != '-' and r[5] == '-' and r[6] == '2' and r[7] == '0' and
r[8] == '1' and (r[9] == '3' or r[9] == '4' or r[9] == '5')) {
if (m >= 1 and m <= 12) {
if (m == 2) {
if (d >= 1 and d <= 28) v[r]++;
} else if (((m <= 7 and m % 2 != 0) or (m >= 8 and m % 2 == 0)) and
d >= 1 and d <= 31)
v[r]++;
else if (d >= 1 and d <= 30)
v[r]++;
}
}
}
for (auto it = v.begin(); it != v.end(); it++) {
if (it->second > x) {
x = it->second;
s2 = it->first;
}
}
cout << s2;
}
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T = 1;
while (T--) {
map<string, int> mp;
string s;
cin >> s;
int n = int((s).size());
for (int i = 0; i < n - 9; i++) {
if (isdigit(s[i]) && s[i + 2] == '-' && s[i + 5] == '-') {
string sub = s.substr(i, 10);
char ch = '-';
int c = count((sub).begin(), (sub).end(), ch);
if (c != 2) {
continue;
}
string D, M, Y;
D = sub.substr(0, 2);
M = sub.substr(3, 2);
Y = sub.substr(6, 4);
int d = stoi(D);
int m = stoi(M);
int y = stoi(Y);
if (y >= 2013 && y <= 2015) {
if (m >= 1 && m <= 12) {
if (m == 2) {
if (d >= 1 && d <= 28) {
mp[sub]++;
}
} else if (m == 4 || m == 6 || m == 9 || m == 11) {
if (d >= 1 && d <= 30) {
mp[sub]++;
}
} else {
if (d >= 1 && d <= 31) {
mp[sub]++;
}
}
}
}
}
}
int maxi = 0;
string ans;
for (auto x : mp) {
if (x.second > maxi) {
maxi = x.second;
ans = x.first;
}
}
cout << ans;
}
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
char s[100005];
char tmp[11];
int yy, dd, mm;
int _map[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int num;
char result[100005][11];
int resultnum[100005];
int check_dd_mm() {
if (_map[mm] >= dd) return 1;
return 0;
}
int add(int point) {
for (int i = 9; i >= 0; i--) tmp[i] = s[point + i - 9];
tmp[10] = '\0';
for (int i = 1; i <= num; i++)
if (!strcmp(tmp, result[i])) {
resultnum[i]++;
return 0;
}
num++;
resultnum[num] = 1;
strcpy(result[num], tmp);
return 0;
}
int check(int i) {
int flag = 1;
if (!(s[i] == '3' || s[i] == '4' || s[i] == '5')) flag = 0;
if (!(s[i - 1] == '1' && s[i - 2] == '0' && s[i - 3] == '2' &&
s[i - 4] == '-' && s[i - 7] == '-')) {
flag = 0;
}
if (!(s[i - 5] >= '0' && s[i - 5] <= '9')) flag = 0;
if (!(s[i - 6] >= '0' && s[i - 6] <= '9')) flag = 0;
if (!(s[i - 8] >= '0' && s[i - 8] <= '9')) flag = 0;
if (!(s[i - 9] >= '0' && s[i - 9] <= '9')) flag = 0;
yy = (s[i] - '0') + 2010;
mm = (s[i - 6] - '0') * 10 + (s[i - 5] - '0');
if (mm <= 0 || mm >= 13) flag = 0;
dd = (s[i - 9] - '0') * 10 + (s[i - 8] - '0');
if (dd <= 0) flag = 0;
if (!flag) return 0;
if (!check_dd_mm()) return 0;
return 1;
}
int main() {
while (gets(s)) {
num = 0;
memset(resultnum, 0, sizeof(resultnum));
int len = strlen(s);
for (int i = 9; i < len; i++) {
if (check(i)) {
add(i);
}
}
int _maxnum = -1;
int _maxpoint;
for (int i = 1; i <= num; i++) {
if (_maxnum < resultnum[i]) {
_maxnum = resultnum[i];
_maxpoint = i;
}
}
printf("%s\n", result[_maxpoint]);
}
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, ans;
char t[11];
cin >> s;
int m[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int len = 0, day = 0, mon = 0, year = 0, flag = 0, cnt, max = 0;
len = s.length();
for (year = 2013; year <= 2015; year++) {
for (mon = 1; mon <= 12; mon++) {
for (day = 1; day <= m[mon]; day++) {
sprintf(t, "%02d-%02d-%04d", day, mon, year);
cnt = 0;
for (int i = 0; i <= len - 10; i++) {
flag = 0;
for (int j = 0; j < 10; j++) {
if (t[j] != s[j + i]) {
flag = 1;
break;
}
}
if (flag == 0) {
cnt++;
}
}
if (cnt > max) {
max = cnt;
ans = t;
}
}
}
}
cout << ans;
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
char str[100005];
int cnt[40][20][4];
bool format[10] = {0, 0, 1, 0, 0, 1, 0, 0, 0, 0};
int dayofmonth[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main() {
scanf("%s", str);
int n = strlen(str);
for (int i = 2; i <= n - 8; i++) {
int st = i - 2;
bool flag = 0;
for (int j = 0; j < 10; j++) {
if ((str[st + j] == '-') != format[j]) {
flag = 1;
break;
}
}
if (flag == 1) continue;
int day = (str[st] - '0') * 10 + (str[st + 1] - '0');
st += 3;
int month = (str[st] - '0') * 10 + (str[st + 1] - '0');
st += 3;
int year = (str[st] - '0') * 1000 + (str[st + 1] - '0') * 100 +
(str[st + 2] - '0') * 10 + (str[st + 3] - '0');
if (year < 2013 || year > 2015 || month < 1 || month > 12 || day < 1 ||
day > dayofmonth[month])
continue;
cnt[day][month][year - 2013]++;
}
int maxcnt = 0;
int d, m, y;
for (int i = 1; i <= 31; i++) {
for (int j = 1; j <= 12; j++) {
for (int k = 0; k < 3; k++) {
if (maxcnt < cnt[i][j][k]) {
maxcnt = cnt[i][j][k];
d = i;
m = j;
y = 2013 + k;
}
}
}
}
printf("%02d-%02d-%4d", d, m, y);
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
char str[100010];
int times[40][15][5];
int monthmaxdays[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool isdigt[11] = {1, 1, 0, 1, 1, 0, 1, 1, 1, 1};
void print(int dd, int mm, int yyyy) {
if (dd < 10)
printf("0%d-", dd);
else
printf("%d-", dd);
if (mm < 10)
printf("0%d-", mm);
else
printf("%d-", mm);
printf("%d\n", yyyy + 2013);
}
int main() {
while (scanf("%s", str) == 1) {
memset(times, 0, sizeof(times));
int len = strlen(str);
for (int i = 0; i + 9 < len; i++) {
bool bl = true;
for (int j = 0; j <= 9; j++)
if ((isdigit(str[i + j])) != isdigt[j]) {
bl = false;
break;
}
if (!bl) continue;
int dd = (str[i] - '0') * 10 + str[i + 1] - '0',
mm = (str[i + 3] - '0') * 10 + str[i + 4] - '0',
yyyy = (str[i + 6] - '0') * 1000 + (str[i + 7] - '0') * 100 +
(str[i + 8] - '0') * 10 + str[i + 9] - '0';
if (mm < 1 || mm > 12 || yyyy < 2013 || yyyy > 2015 || dd < 1 ||
dd > monthmaxdays[mm])
continue;
times[dd][mm][yyyy - 2013]++;
}
int dd = 1, mm = 1, yyyy = 0;
for (int y = 0; y <= 2; y++)
for (int m = 1; m <= 12; m++)
for (int d = 1; d <= monthmaxdays[m]; d++) {
if (times[d][m][y] > times[dd][mm][yyyy]) dd = d, mm = m, yyyy = y;
}
print(dd, mm, yyyy);
}
}
| 8 |
CPP
|
def is_number(str):
try:
int(str)
return True
except ValueError:
return False
def solution(a,b,c):
if 2013<=c<=2015:
if b==2 and a<29:
return True
elif b in [1,3,5,7,8,10,12] and 0<a<32:
return True
elif b in [4,6,9,11] and 0<a<31:
return True
s=input()
test={}
for i in range(0,len(s)-9):
t=s[i:i+10]
#print(t[:2],' ',t[3:5],' ',t[6:])
if is_number(t[:2]) and is_number(t[3:5]) and is_number(t[6:]):
#print(t,' ','ok')
year=int(t[6:])
month=int(t[3:5])
day=int(t[:2])
if solution(int(day),int(month),int(year)) and t.count('-')==2:
if t in test:
test[t]+=1
else:
test[t]=1
mx=-1
for i in test:
if test[i] > mx:
mx=test[i]
for i in test:
if test[i] == mx:
print(i)
quit()
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
const double eps = 1e-9;
const int mod = 1000007;
const int inf = 0x7fffffff;
const int maxlog = 33;
template <class Int>
inline int size(const Int &a) {
return (int)a.size();
}
map<string, int> mapp;
const int MONTH_DAYS[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool valid(string x) {
for (__typeof(size(x)) i = 0; i < (size(x)); i++)
if (x[i] == '-') x[i] = ' ';
int cnt = count(x.begin(), x.end(), ' ');
if (cnt > 2) return false;
int d, m, y;
istringstream buff;
buff.clear();
buff.str(x);
buff >> d >> m >> y;
if (m < 1 || m > 12 || d < 1 || d > MONTH_DAYS[m] || y < 2013 || y > 2015)
return false;
if (x[1] == ' ') return false;
if (x[4] == ' ') return false;
return true;
}
int main() {
string line;
int maxi = 0;
getline(cin, line);
for (__typeof(size(line) - 9) i = 0; i < (size(line) - 9); i++) {
string temp = line.substr(i, 10);
if (valid(temp)) {
mapp[temp]++;
maxi = max(mapp[temp], maxi);
}
}
if (valid(line)) {
mapp[line]++;
maxi = max(maxi, mapp[line]);
}
for (__typeof((mapp).begin()) i = (mapp).begin(); i != (mapp).end(); i++) {
if (maxi == i->second) {
cout << i->first << endl;
return 0;
}
}
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
template <class X>
class vec {
public:
X x, y;
vec<X>(X a = 0, X b = 0) { x = a, y = b; }
X dis(vec a) { return (x - a.x) * (x - a.x) + (y - a.y) * (y - a.y); }
vec<X> operator-(vec<X> b) { return vec<X>(x - b.x, y - b.y); }
X operator*(vec<X> b) { return x * b.y - y * b.x; }
};
void sf(int &x) { scanf("%d", &x); }
void sf(long long &x) { scanf("%lld", &x); }
void sf(long long &x, long long &y) { scanf("%lld%lld", &x, &y); }
void sf(float &x) { scanf("%f", &x); }
void sf(double &x) { scanf("%lf", &x); }
void sf(int &x, int &y) { scanf("%d%d", &x, &y); }
void sf(float &x, float &y) { scanf("%f%f", &x, &y); }
void sf(double &x, double &y) { scanf("%lf%lf", &x, &y); }
void sf(double &x, double &y, double &z) { scanf("%lf%lf%lf", &x, &y, &z); }
void sf(int &x, int &y, int &z) { scanf("%d%d%d", &x, &y, &z); }
void sf(long long &x, long long &y, long long &z) {
scanf("%lld%lld%lld", &x, &y, &z);
}
void sf(float &x, float &y, float &z) { scanf("%u%u%u", &x, &y, &z); }
void sf(char &x) { x = getchar(); }
void sf(char *s) { scanf("%s", s); }
void sf(string &s) { cin >> s; }
void sf(vec<int> &x) {
int a, b;
sf(a, b);
x = vec<int>(a, b);
}
void pf(int x) { printf("%d\n", x); }
void pf(int x, int y) { printf("%d %d\n", x, y); }
void pf(int x, int y, int z) { printf("%d %d %d\n", x, y, z); }
void pf(long long x) { printf("%lld\n", x); }
void pf(long long x, long long y) { printf("%lld %lld\n", x, y); }
void pf(long long x, long long y, long long z) {
printf("%lld %lld %lld\n", x, y, z);
}
void pf(float x) { printf("%u\n", x); }
void pf(double x) { printf("%.9lf\n", x); }
void pf(double x, double y) { printf("%.5lf %.5lf\n", x, y); }
void pf(char x) { printf("%c\n", x); }
void pf(char *x) { printf("%s\n", x); }
void pf(string x) {
cout << x;
puts("");
}
void pf(vec<int> x) { printf("%d %d\n", x.x, x.y); }
long long STN(string s) {
long long sm;
stringstream ss(s);
ss >> sm;
return sm;
}
template <class T>
T bigmod(T b, T p, T m) {
if (p == 0) return 1 % m;
T x = b;
T ans = 1;
while (p) {
if (p & 1) ans = (ans * x) % m;
p >>= 1;
x = (x * x) % m;
}
return ans;
}
template <class T>
T gcd(T x, T y) {
if (y == 0) return x;
return gcd(y, x % y);
}
template <typename T>
T POW(T b, T p) {
if (p == 0) return 1;
if (p == 1) return b;
if (p % 2 == 0) {
T s = POW(b, p / 2);
return s * s;
}
return b * POW(b, p - 1);
}
template <typename T>
T modinv(T num, T m) {
return bigmod(num, m - 2, m);
}
template <class T>
string NTS(T Number) {
stringstream ss;
ss << Number;
return ss.str();
}
string s, as;
map<string, int> mp;
int an = 0, dx[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main() {
sf(s);
int l = s.size();
for (int i = 0, j = 9; j < l; i++, j++) {
int a = 0;
int b = 0;
bool f = 1;
if (s[i + 2] != '-' || s[i + 5] != '-') f = 0;
string ss, gg, gm, gd;
for (int k = i; k <= j; k++) {
ss += s[k];
if (s[k] >= '0' && s[k] <= '9')
a++;
else
b++;
}
gg = s.substr(i + 6, 4);
gm = s.substr(i + 3, 2);
gd = s.substr(i, 2);
int ag = STN(gg), ad = STN(gd);
if (a != 8) f = 0;
if (f) mp[ss]++;
int ab = mp[ss], am = STN(gm);
if (ag >= 2013 && ag <= 2015 && ad > 0 && ad <= dx[am] && ab > an) {
an = ab;
as = ss;
}
}
pf(as);
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
string s;
map<string, int> m;
string ans;
int bns = 0;
int dd[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool check(string s) {
string ss;
ss = s.substr(5, 5);
if (ss != "-2013" && ss != "-2014" && ss != "-2015") return false;
if (s[2] != '-') return false;
if (!isdigit(s[0]) || !isdigit(s[1]) || !isdigit(s[3]) || !isdigit(s[4]))
return false;
int m = (s[3] - '0') * 10 + (s[4] - '0');
int d = (s[0] - '0') * 10 + (s[1] - '0');
if (m > 12 || m == 0) return false;
if (d > dd[m] || d == 0) return false;
return true;
}
int main() {
ios::sync_with_stdio(false);
cin >> s;
for (int i = 0; i < s.size() - 9; i++) {
string ss = s.substr(i, 10);
if (check(ss)) m[ss]++;
}
for (auto i : m) {
if (i.second > bns) {
ans = i.first;
bns = i.second;
}
}
cout << ans << endl;
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
int w[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
string s;
int getint(string p) {
int res = 0;
for (int j = 0; j < p.length(); j++)
if (p[j] == '-')
return -1;
else {
res = res * 10 + (p[j] - '0');
}
return res;
}
map<string, int> mm;
map<string, int>::iterator it;
int main() {
cin >> s;
string ans;
int m = 0, index;
for (int i = 0; i < s.length(); i++)
if (s[i] == '-' && i >= 2 && i <= s.length() - 4) {
int k1 = getint(s.substr(i - 2, 2));
int k2 = getint(s.substr(i + 1, 2));
int k3 = getint(s.substr(i + 4, 4));
if (k2 > 0 && k2 < 13)
if (k1 > 0 && k1 <= w[k2])
if (k3 >= 2013 && k3 <= 2015) {
string s1 = s.substr(i - 2, 10);
mm[s1]++;
}
}
for (it = mm.begin(); it != mm.end(); it++)
if (m < it->second) m = it->second, ans = it->first;
cout << ans;
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
char s[100006], wc[13];
bool ok[10];
long D[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
map<string, long> MAP;
long anss;
string ans, now;
int main() {
std::ios::sync_with_stdio(false);
long i, j, d, m, y;
cin >> s;
ok[2] = ok[5] = 1;
for (i = 0; s[i + 9] != '\0'; ++i) {
for (j = 0; j < 10; ++j)
if ((s[j + i] == '-') != ok[j]) break;
if (j == 10) {
for (j = 0; j < 10; ++j) wc[j] = s[j + i];
wc[10] = '\0';
now = wc;
d = (now[0] - '0') * 10 + (now[1] - '0');
m = (now[3] - '0') * 10 + (now[4] - '0');
y = (now[6] - '0') * 1000 + (now[7] - '0') * 100 + (now[8] - '0') * 10 +
(now[9] - '0');
if (m > 12 || m == 0 || y < 2013 || y > 2015) continue;
if (d > D[m] || d == 0) continue;
if (++MAP[now] > anss) {
anss = MAP[now];
ans = now;
}
}
}
cout << ans << endl;
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1000 + 5;
const int mod = 1000 * 1000 * 1000 + 7;
int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int num(string s) {
int res = 0;
for (int i = 0; i < ((int)(s).size()); i++) {
if (s[i] < '0' || s[i] > '9') return -1;
res = res * 10 + s[i] - '0';
}
return res;
}
bool valid(string s) {
if (s[2] != '-' || s[5] != '-') return 0;
int d = num(s.substr(0, 2)), m = num(s.substr(3, 2)), y = num(s.substr(6));
if (y < 2013 || y > 2015) return 0;
if (m < 1 || m > 12) return 0;
if (d < 1 || d > days[m - 1]) return 0;
return 1;
}
int main() {
ios_base::sync_with_stdio(false);
string s;
cin >> s;
map<string, int> d;
for (int i = 0; i < ((int)(s).size()) - 9; i++) {
string dt = s.substr(i, 10);
d[dt] += valid(dt);
}
string out;
int maxx = 0;
for (__typeof(d.begin()) it = d.begin(); it != d.end(); it++)
if (it->second > maxx) {
maxx = it->second;
out = it->first;
}
cout << out << endl;
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int arr[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
char str[maxn];
map<string, int> mp;
struct CmpByValue {
bool operator()(const pair<string, int>& lhs, const pair<string, int>& rhs) {
return lhs.second > rhs.second;
}
};
int check(int x) {
int flag[5] = {0}, numd = 0, numm = 0, numy = 0;
if (isdigit(str[x - 1]) && isdigit(str[x - 2]))
flag[0] = 1, numd = (str[x - 2] - '0') * 10 + (str[x - 1] - '0');
if (isdigit(str[x + 1]) && isdigit(str[x + 2]))
flag[1] = 1, numm = (str[x + 1] - '0') * 10 + (str[x + 2] - '0');
for (int i = x + 4; i < x + 8; i++)
if (isdigit(str[i]))
numy = numy * 10 + (str[i] - '0');
else
return 0;
if (flag[0] && flag[1]) {
if (2013 <= numy && numy <= 2015) {
if (1 <= numm && numm <= 12) {
if (0 < numd && numd <= arr[numm])
return 1;
else
return 0;
} else
return 0;
} else
return 0;
} else
return 0;
}
int main() {
scanf("%s", str);
int n = strlen(str);
for (int i = 0; i < n; i++) {
if (str[i] == '-' && str[i + 3] == '-') {
if (i - 2 < 0 || i + 7 >= n) continue;
if (check(i)) {
string s;
for (int j = i - 2; j <= i + 7; j++) s += str[j];
mp[s]++;
}
}
}
vector<pair<string, int> > vec(mp.begin(), mp.end());
sort(vec.begin(), vec.end(), CmpByValue());
pair<string, int> p = vec[0];
cout << p.first << endl;
return 0;
}
| 8 |
CPP
|
s=input()
temp=[]
tem=[]
c=0
mon=[31,28,31,30,31,30,31,31,30,31,30,31]
f={}
for i in range(len(s)-10+1):
x=s[i:i+10]
if x[2]=='-' and x[5]=='-' and x.count('-')==2:
#print(i)
y=int(x[0:2])
yy=int(x[3:5])
yyy=int(x[-4:])
#print(y,yy,yyy)
if yyy>=2013 and yyy<=2015:
if yy>=1 and yy<=12:
if y<=mon[yy-1] and y>=1:
try:
f[x]+=1
except:
f[x]=1
ff={v:k for k,v in f.items()}
print(ff[max(ff.keys())])
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
bool tep(pair<string, int> a, pair<string, int> b) {
return a.second > b.second;
}
bool f(string s) {
for (int i = 0; i < 10; i++) {
if ((i == 2 || i == 5) && s[i] != '-') return 0;
if ((i != 2 && i != 5) && s[i] == '-') return 0;
}
if (s.substr(6) != "2013" && s.substr(6) != "2014" && s.substr(6) != "2015")
return 0;
if ((s[3] != '0' && s[4] != '0' && s[4] != '1' && s[4] != '2') ||
s[3] > '1' || (s[3] == '0' && s[4] == '0'))
return 0;
if (s.substr(0, 2) == "00") return 0;
if (s.substr(3, 2) == "02" && (s[0] >= '3' || (s[0] == '2' && s[1] > '8')))
return 0;
if ((s.substr(3, 2) == "04" || s.substr(3, 2) == "06" ||
s.substr(3, 2) == "09" || s.substr(3, 2) == "11") &&
(s[0] > '3' || (s[0] == '3' && s[1] > '0')))
return 0;
else if (s.substr(3, 2) != "02" &&
(s[0] > '3' || (s[0] == '3' && s[1] > '1')))
return 0;
return 1;
}
int main() {
string str;
vector<pair<string, int> > x;
int xn = 0;
cin >> str;
for (int i = 0; i < str.length() - 9; i++) {
string ss = str.substr(i, 10);
if (f(ss)) {
int j;
for (j = 0; j < xn; j++)
if (ss == x[j].first) {
x[j].second++;
break;
}
if (j == xn) {
xn++;
x.push_back(make_pair(ss, 1));
}
}
}
pair<string, int> xx[xn];
for (int i = 0; i < xn; i++) {
xx[i].first = x[i].first;
xx[i].second = x[i].second;
}
sort(xx, xx + xn, tep);
cout << xx[0].first << endl;
return 0;
}
| 8 |
CPP
|
'''
def main():
from sys import stdin,stdout
if __name__=='__main__':
main()
'''
#349B
'''
def main():
from sys import stdin,stdout
N = int(stdin.readline())
arr = list(map(int,stdin.readline().split()))
div = []
for i in arr:
div.append(N//i)
maxim = 0
maxindex = -1
for i in range(9):
if div[i] >maxim:
maxim = div[i]
maxindex = i
if maxindex > -1:
ans = [ (maxindex+1) for i in range(maxim)]
N= N%arr[maxindex]
#print(N)
i = 0
while i<maxim:
#print('i=',i,'N=',N)
for j in range(8,maxindex,-1):
#print('j=',j,'diff=',arr[j]-arr[ans[i]-1])
if arr[j]-arr[ans[i]-1] <=N:
N -= arr[j]-arr[ans[i]-1]
ans[i] = j+1
break
i+=1
for i in ans:
stdout.write(str(i))
else:
stdout.write('-1\n')
if __name__=='__main__':
main()
'''
#234B Input and Output
'''
def main():
from sys import stdin,stdout
import collections
with open('input.txt','r') as ip:
N,K = map(int,ip.readline().split())
arr = list(map(int,ip.readline().split()))
mydict = collections.defaultdict(set)
for i in range(len(arr)):
mydict[arr[i]].add(i+1)
ans = []
i=0
while K>0:
for it in mydict[sorted(mydict.keys(),reverse=True)[i]]:
ans.append(it)
K-=1
if K<1:
break
minim=i
i+=1
with open('output.txt','w') as out:
out.write(str(sorted(mydict.keys(),reverse=True)[minim])+'\n')
ans=' '.join(str(x) for x in ans)
out.write(ans+'\n')
if __name__=='__main__':
main()
'''
#151B
'''
def main():
from sys import stdin,stdout
import collections
names = collections.defaultdict(list)
counter = 0
order = {}
for i in range(int(stdin.readline())):
n,ns = stdin.readline().split()
names[ns]=[0,0,0]
order[ns]=counter
counter+=1
n=int(n)
while n:
ip=stdin.readline().strip()
ip=ip.replace('-','')
#test for taxi
flag=True
for i in range(1,6):
if ip[i]!=ip[0]:
flag=False
break
if flag:
names[ns][0]+=1
n-=1
continue
#test for pizza
flag = True
for i in range(1,6):
if int(ip[i])>=int(ip[i-1]):
flag =False
break
if flag:
names[ns][1]+=1
else:
names[ns][2]+=1
n-=1
#print(names)
#for all girls
t=-1
p=-1
g=-1
for i in names:
t=max(t,names[i][0])
p = max(p, names[i][1])
g = max(g, names[i][2])
taxi=list(filter(lambda x: names[x][0]==t, names.keys()))
pizza = list(filter(lambda x: names[x][1] == p, names.keys()))
girls = list(filter(lambda x: names[x][2] == g, names.keys()))
pizza.sort(key= lambda x: order[x])
taxi.sort(key= lambda x: order[x])
girls.sort(key= lambda x: order[x])
print('If you want to call a taxi, you should call:',', '.join(x for x in taxi),end='.\n')
print('If you want to order a pizza, you should call:', ', '.join(x for x in pizza),end='.\n')
print('If you want to go to a cafe with a wonderful girl, you should call:', ', '.join(x for x in girls),end='.\n')
if __name__=='__main__':
main()
'''
#SQUADRUN Q2
'''
def LCMgen(a):
import math
lcm = a[0]
for i in range(1,len(a)):
g = math.gcd(lcm,a[i])
lcm = (lcm*a[i])//g
return lcm
def main():
from sys import stdin,stdout
import collections
import math
N,W = map(int,stdin.readline().split())
counter = collections.Counter(map(int,stdin.readline().split()))
lcm = LCMgen(list(counter.keys()))
W*=lcm
div = 0
for i in counter:
div+=counter[i]*(lcm//i)
ans = math.ceil(W/div)
stdout.write(str(ans))
if __name__=='__main__':
main()
'''
#143B
'''
def main():
from sys import stdin,stdout
ip = stdin.readline().strip()
inte = None
flow = None
for i,j in enumerate(ip):
if j=='.':
flow = ip[i:]
inte = ip[:i]
break
if flow == None:
flow = '.00'
inte = ip
else:
if len(flow)==2:
flow+='0'
else:
flow = flow[:3]
ne = False
if ip[0]=='-':
ne = True
if ne:
inte = inte[1:]
inte = inte[::-1]
ans =''
for i,j in enumerate(inte):
ans += j
if i%3 == 2:
ans+=','
ans = ans[::-1]
if ans[0]==',':
ans = ans[1:]
ans = '$'+ans
if ne:
stdout.write('({})'.format(ans+flow))
else:
stdout.write(ans+flow)
if __name__=='__main__':
main()
'''
#A
'''
def main():
from sys import stdin,stdout
n = int(stdin.readline())
arr = list(map(int,stdin.readline().split()))
minim = min(arr)
my_l = []
for i,j in enumerate(arr):
if j==minim:
my_l.append(i)
my_l_ = []
for i in range(1,len(my_l)):
my_l_.append(my_l[i]-my_l[i-1])
stdout.write(str(min(my_l_)))
if __name__=='__main__':
main()
'''
#B
'''
def main():
from sys import stdin,stdout
n,a,b = map(int,stdin.readline().split())
maxim = -1
for i in range(1,n):
maxim = max(min(a//i,b//(n-i)),maxim)
stdout.write(str(maxim))
if __name__=='__main__':
main()
'''
#233B
'''
def main():
from sys import stdin,stdout
def foo(x):
tsum = 0
c = x
while c:
tsum+=(c%10)
c//=10
return tsum
N = int(stdin.readline())
up,down = 0 , int(1e18)
flag = False
while up<down:
mid = (up+down)//2
val = foo(mid)
val = (mid+val)*mid
if val<N:
up = mid
elif val >N:
down = mid
else:
flag=True
break
if flag:
stdout.write(str(mid)+'\n')
else:
stdout.write('-1')
if __name__=='__main__':
main()
def main():
def foo(x):
n= x
tsum = 0
while n:
tsum += n%10
n//=10
return x*x + tsum*x - int(1e18)
import matplotlib.pyplot as plt
y = [foo(x) for x in range(1,int(1e18)+1)]
x = range(1,int(1e18)+1)
print(y[:100])
plt.plot(y,x)
plt.show()
if __name__=='__main__':
main()
'''
#RECTANGL
'''
def main():
from sys import stdin,stdout
import collections
for _ in range(int(stdin.readline())):
c = collections.Counter(list(map(int,stdin.readline().split())))
flag = True
for i in c:
if c[i]&1:
flag=False
if flag:
stdout.write('YES\n')
else:
stdout.write('NO\n')
if __name__=='__main__':
main()
'''
#MAXSC
'''
def main():
from sys import stdin,stdout
import bisect
for _ in range(int(stdin.readline())):
N = int(stdin.readline())
mat = []
for i in range(N):
mat.append(sorted(map(int,stdin.readline().split())))
## print(mat)
temp = mat[-1][-1]
tsum = mat[-1][-1]
flag = True
for i in range(N-2,-1,-1):
ind = bisect.bisect_left(mat[i],temp)-1
if ind == -1:
flag = False
break
else:
tsum+=mat[i][ind]
if flag:
stdout.write(str(tsum)+'\n')
else:
stdout.write('-1\n')
if __name__=='__main__':
main()
'''
#233B ********************
'''
def main():
def rev(x):
tsum = 0
while x:
tsum += x%10
x//=10
return tsum
from sys import stdin,stdout
from math import sqrt,ceil
n = int(stdin.readline())
for i in range(91):
r = i*i+(n<<2)
x = ceil(sqrt(r))
## print(i,x)
if x*x == r:
num = (x-i)/2
if num == int(num):
if rev(num)==i:
stdout.write(str(int(num)))
return
stdout.write('-1')
if __name__=='__main__':
main()
'''
#228B
'''
def main():
from sys import stdin,stdout
na,nb = map(int,stdin.readline().split())
A = []
for _ in range(na):
A.append([int(x) for x in stdin.readline().strip()])
ma,mb = map(int,stdin.readline().split())
B= []
for _ in range(ma):
B.append([int(x) for x in stdin.readline().strip()])
## print(A)
## print(B)
maxim , value = -1, None
for x in range(1-na,ma):
for y in range(1-nb,mb):
tmp = 0
for i in range(na):
for j in range(nb):
if i+x > -1 and i+x <ma and i>-1 and i<na and j>-1 and j<nb and j+y > -1 and j+y <mb:
tmp+=A[i][j]*B[i+x][j+y]
## print(x,y,tmp)
if tmp > maxim:
maxim = tmp
value = (x,y)
## print("MAXIM:",maxim,"VALUE:",value)
stdout.write(str(value[0])+' '+str(value[1]))
if __name__=='__main__':
main()
'''
#260B
def main():
import re , collections, datetime
from sys import stdin,stdout
def post_process(ans):
datetime.MINYEAR=2013
datetime.MAXYEAR=2015
for string in ans:
dd,mm,yyyy = map(int,string.split('-'))
try:
obj = datetime.date(yyyy,mm,dd)
except:
ans[string]=0
return ans
my_re = '(?=([0-9][0-9]-[0-1][0-9]-201[3-5]))'
inp = stdin.readline().strip()
ans = re.finditer(my_re,inp)
ans = collections.Counter([m.group(1) for m in ans])
ans = post_process(ans)
stdout.write(ans.most_common(1)[0][0])
if __name__=='__main__':
main()
| 8 |
PYTHON3
|
#-------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
def value():
return map(int,input().split())
def array():
return [int(i) for i in input().split()]
#-------------------------code---------------------------#
#vsInput()
s=input()
n=len(s)
years=[2013,2014,2015]
ans=defaultdict(int)
days=[31,28,31,30,31,30,31,31,30,31,30,31]
date=''
i=0
while(i<n-9):
k=s[i:i+10]
i+=1
try:
d=int(k[0:2])
m=int(k[3:5])
y=int(k[6:])
except:
continue
if(k[2]==k[5] and k[2]=='-'):
if(y in years and m<=12 and d<=days[m-1] and d!=0):
ans[k]+=1
if(ans[k]>ans[date]):
date=k
print(date)
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
map<int, int> m;
map<int, int>::iterator it;
int mesec(int m) {
if (m == 1)
return 31;
else if (m == 2)
return 28;
else if (m == 3)
return 31;
else if (m == 4)
return 30;
else if (m == 5)
return 31;
else if (m == 6)
return 30;
else if (m == 7)
return 31;
else if (m == 8)
return 31;
else if (m == 9)
return 30;
else if (m == 10)
return 31;
else if (m == 11)
return 30;
else if (m == 12)
return 31;
else
return -1;
}
int main() {
char a[100011];
cin.get(a, 100011);
long long int q1, q2, q3, q4, q5, mx = 0;
for (int i = 2; i < strlen(a); i++) {
if (a[i] == '-') {
if (a[i - 1] >= '0' && a[i - 1] <= '9')
if (a[i - 2] >= '0' && a[i - 2] <= '9')
if (a[i + 1] >= '0' && a[i + 1] <= '9')
if (a[i + 2] >= '0' && a[i + 2] <= '9')
if (a[i + 3] == '-' && a[i + 3] == '-')
if (a[i + 4] >= '0' && a[i + 4] <= '9')
if (a[i + 5] >= '0' && a[i + 5] <= '9')
if (a[i + 6] >= '0' && a[i + 6] <= '9')
if (a[i + 7] >= '0' && a[i + 7] <= '9') {
q1 = (a[i - 2] - '0') * 10 + (a[i - 1] - '0');
q2 = (a[i + 1] - '0') * 10 + (a[i + 2] - '0');
q3 = (a[i + 4] - '0') * 1000 + (a[i + 5] - '0') * 100 +
(a[i + 6] - '0') * 10 + (a[i + 7] - '0');
if (q1 >= 1 && q1 <= mesec(q2))
if (q3 >= 2013 && q3 <= 2015) {
q4 = q1 * 1000000 + q2 * 10000 + q3;
m[q4]++;
if (m[q4] > mx) {
mx = m[q4];
q5 = q4;
}
}
}
}
}
if (q5 / 1000000 < 10) cout << 0;
cout << q5 / 1000000 << "-";
if (q5 / 10000 % 100 < 10) cout << 0;
cout << q5 / 10000 % 100 << "-";
cout << q5 % 10000 << endl;
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
const int d[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int o[31][12][3];
bool isDigit(char c) { return '0' <= c && c <= '9'; }
int toInt(char c) { return c - '0'; }
int main() {
char t[100001];
scanf("%s", t);
int l = strlen(t);
for (int i = 0; i <= l - 10; i++) {
if (isDigit(t[i]) && isDigit(t[i + 1]) && isDigit(t[i + 3]) &&
isDigit(t[i + 4]) && isDigit(t[i + 6]) && isDigit(t[i + 7]) &&
isDigit(t[i + 8]) && isDigit(t[i + 9]))
if (t[i + 2] == '-' && t[i + 5] == '-') {
int a = 10 * toInt(t[i]) + toInt(t[i + 1]);
int b = 10 * toInt(t[i + 3]) + toInt(t[i + 4]);
int c = 1000 * toInt(t[i + 6]) + 100 * toInt(t[i + 7]) +
10 * toInt(t[i + 8]) + toInt(t[i + 9]);
if (1 <= b && b <= 12)
if (1 <= a && a <= d[b - 1])
if (2013 <= c && c <= 2015) o[a - 1][b - 1][c - 2013]++;
}
}
int i = 0, j = 0, k = 0;
for (int a = 0; a < 31; a++)
for (int b = 0; b < 12; b++)
for (int c = 0; c < 3; c++)
if (o[a][b][c] > o[i][j][k]) {
i = a;
j = b;
k = c;
}
printf("%s%d-%s%d-%d\n", i + 1 < 10 ? "0" : "", i + 1, j + 1 < 10 ? "0" : "",
j + 1, k + 2013);
return 0;
}
| 8 |
CPP
|
s = input()
nums = set([str(x) for x in range(0, 9+1)])
cnt = dict()
m = -1
ans = 0
days_in_month = {1: 31, 2: 28, 3: 31, 4: 30, 5: 31, 6: 30, 7: 31, 8: 31, 9: 30, 10: 31, 11: 30, 12:31}
for i in range(len(s) - 10+1):
q = s[i:i+10]
if q[0] in nums and q[1] in nums and q[2] == "-":
if q[3] in nums and q[4] in nums and q[5] == "-":
if q[6] in nums and q[7] in nums and q[8] in nums and q[9] in nums:
try:
day = int(q[0:1+1])
month = int(q[3:4+1])
year = int(q[6:9+1])
except:
continue
#print(day, month)
if 0 < month <= 12 and 0 < day <= days_in_month[month] and 2013 <= year <= 2015:
try:
cnt[q] += 1
except:
cnt[q] = 0
#print(cnt)
for key in cnt.keys():
if cnt[key] > m:
m = cnt[key]
ans = key
print(ans)
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
const int mod = int(1e9 + 7);
const double PI = acos(-1.0);
int m[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int func(string second) {
int i, sum = 0;
for (i = 0; i < second.length(); i++) sum = sum * 10 + (int)second[i] - 48;
return sum;
}
int ms, k, kk, g, i;
map<string, int> mm;
pair<int, string> a[100000];
vector<string> v;
int main() {
string second, t;
getline(cin, second);
t = "";
i = 0;
while (i < second.length()) {
if (second[i] == '-') {
v.push_back(t);
t = "";
} else
t += second[i];
i++;
}
if (t != "") v.push_back(t);
for (i = 0; i < v.size() - 2; i++) {
if ((v[i].length() > 1) && (v[i + 1].length() == 2) &&
(v[i + 2].length() > 3)) {
t = v[i].substr(v[i].length() - 2);
k = func(t);
t += "-" + v[i + 1] + "-";
kk = func(v[i + 1]);
if ((kk < 13) && (kk > 0) && (k > 0) && (k <= m[kk])) {
second = v[i + 2].substr(0, 4);
t += second;
g = func(second);
if ((g > 2012) && (g < 2016)) {
if (mm[t] == 0) {
mm[t] = ++ms;
a[ms].second = t;
}
a[mm[t]].first++;
}
}
}
}
g = 1;
for (i = 2; i <= ms; i++)
if (a[i].first > a[g].first) g = i;
cout << a[g].second;
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
struct Node {
int y, m, d;
Node(int y = 0, int m = 0, int d = 0) : y(y), m(m), d(d) {}
bool operator<(const Node &b) const {
if (y != b.y) return y < b.y;
if (m != b.m) return m < b.m;
return d < b.d;
}
void out() { printf("%02d-%02d-%04d\n", d, m, y); }
};
const int b[8] = {0, 1, 3, 4, 6, 7, 8, 9};
const int f[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
char s[200005];
map<Node, int> mp;
inline int val(char c) { return c - '0'; }
inline int day(char *a) { return val(a[0]) * 10 + val(a[1]); }
inline int month(char *a) { return val(a[0]) * 10 + val(a[1]); }
inline int year(char *a) { return day(a) * 100 + day(a + 2); }
void gao(char *a) {
int y, m, d;
for (int i = 0; i < 8; ++i)
if (!isdigit(a[b[i]])) return;
if (a[2] != '-' || a[5] != '-') return;
d = day(a);
m = month(a + 3);
if (m < 1 || m > 12) return;
if (d < 1 || d > f[m]) return;
y = year(a + 6);
if (y < 2013 || y > 2015) return;
++mp[Node(y, m, d)];
}
int main() {
scanf("%s", s);
int n = strlen(s);
for (int i = 0; i + 10 <= n; ++i) gao(s + i);
Node ans;
int cnt = -1;
for (map<Node, int>::iterator it = mp.begin(); it != mp.end(); ++it)
if (it->second > cnt) {
cnt = it->second;
ans = it->first;
}
ans.out();
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int xx = (int)1e6 + 1;
bool sortinrev(const pair<long long int, long long int> &a,
const pair<long long int, long long int> &b) {
return (a.first > b.first);
}
long long int A[1000000];
long long int B[1000000];
map<long long int, vector<long long int> > ps;
map<string, long long int> mp;
void fun() {
mp["01"] = 31;
mp["02"] = 28;
mp["03"] = 31;
mp["04"] = 30;
mp["05"] = 31;
mp["06"] = 30;
mp["07"] = 31;
mp["08"] = 31;
mp["09"] = 30;
mp["10"] = 31;
mp["11"] = 30;
mp["12"] = 31;
}
map<string, long long int> cnt;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
fun();
string s, result;
cin >> s;
long long int mx = 0;
for (long long int i = 0; i <= ((int)(s).size()) - 10; i++) {
string h = s.substr(i, 10), x = h.substr(6, 4), y = h.substr(3, 2);
if (h[0] >= '0' && h[1] >= '0' && h[2] == '-' && h[5] == '-' &&
mp[y] != 0 && (x == "2013" || x == "2014" || x == "2015")) {
long long int val = (h[0] - '0') * 10;
val += (h[1] - '0');
if (val <= mp[y] && val != 0) {
cnt[h]++;
if (cnt[h] > mx) result = h, mx = cnt[h];
}
}
}
cout << result << endl;
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
template <class T, class L>
bool smax(T &x, L y) {
return x < y ? (x = y, 1) : 0;
}
template <class T, class L>
bool smin(T &x, L y) {
return y < x ? (x = y, 1) : 0;
}
const int maxn = 1e5 + 17;
char s[maxn];
int n, mx[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
map<string, int> mp;
void check(char *s) {
for (int i = 0; i < 10; i++)
if ((i == 2 || i == 5) ^ (s[i] == '-')) return;
string y(s + 6, s + 10);
if (y != "2013" && y != "2014" && y != "2015") return;
int m = (s[3] - '0') * 10 + (s[4] - '0');
if (m < 1 || 12 < m) return;
int d = (s[0] - '0') * 10 + (s[1] - '0');
if (d < 1 || d > mx[m]) return;
mp[string(s, s + 10)]++;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
scanf("%s", s), n = strlen(s);
for (int i = 0; i <= n - 10; i++) check(s + i);
int mx = 0;
for (auto &x : mp) smax(mx, x.second);
for (auto &x : mp)
if (x.second == mx) cout << x.first << '\n';
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
char str[100001];
int cou[32][13][2020];
int months[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool isnum(char c) {
if (c >= '0' && c <= '9') return true;
return false;
}
bool isleap(int year) {
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) return true;
return false;
}
int main() {
while (scanf("%s", str) != EOF) {
memset(cou, 0, sizeof(cou));
int month, year, day, dcount = 0;
month = 0, year = 0, day = 0;
int len = strlen(str), ans = 0, y = 0, m = 0, d = 0;
for (int i = 0; i < len; i++) {
if (isnum(str[i]) && (i + 9) < len) {
if (isnum(str[i + 1]) && !isnum(str[i + 2]) && isnum(str[i + 3]) &&
isnum(str[i + 4]) && !isnum(str[i + 5]) && isnum(str[i + 6]) &&
isnum(str[i + 7]) && isnum(str[i + 8]) && isnum(str[i + 9])) {
day = (str[i] - '0') * 10 + str[i + 1] - '0';
if (day > 31 || day == 0) continue;
month = (str[i + 3] - '0') * 10 + str[i + 4] - '0';
if (month > 12) continue;
year = (str[i + 6] - '0') * 1000 + (str[i + 7] - '0') * 100 +
(str[i + 8] - '0') * 10 + str[i + 9] - '0';
if (year < 2013 || year > 2015) continue;
if (day > months[month]) continue;
cou[day][month][year]++;
if (ans < cou[day][month][year]) {
d = day;
m = month;
y = year;
ans = cou[day][month][year];
}
}
}
}
printf("%02d-%02d-%d\n", d, m, y);
}
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
string s;
int main() {
map<string, string> month;
month["01"] = "31";
month["02"] = "28";
month["03"] = "31";
month["04"] = "30";
month["05"] = "31";
month["06"] = "30";
month["07"] = "31";
month["08"] = "31";
month["09"] = "30";
month["10"] = "31";
month["11"] = "30";
month["12"] = "31";
cin >> s;
for (int i = int(s.size() - 1); i >= 9; i--) {
string temp = s.substr(i - 3, 4);
if (temp == "2013" || temp == "2014" || temp == "2015") {
mp[s.substr(i - 9, 10)]++;
}
}
string ans = "";
int mx = -1;
for (map<string, int>::iterator it = mp.begin(); it != mp.end(); it++) {
if (it->second > mx) {
string temp = it->first;
string m = temp.substr(3, 2);
string d = temp.substr(0, 2);
if (d[0] == '-' || d[1] == '-' || m[0] == '-' || m[1] == '-' ||
m[0] > '1' || (m[0] == '1' && m[1] > '2') ||
(m[0] == '0' && m[1] == '0') || (d[0] == '0' && d[1] == '0') ||
temp[2] != '-' || temp[5] != '-')
continue;
if (month[m] >= d) {
mx = it->second;
ans = it->first;
}
}
}
cout << ans << endl;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
long long int M = 1000000007;
long long int gcd(long long int a, long long int b) {
return (b == 0) ? a : gcd(b, a % b);
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int t = 1;
while (t--) {
map<string, string> months;
months["01"] = "31";
months["02"] = "28";
months["03"] = months["05"] = months["07"] = months["08"] = months["10"] =
months["12"] = "31";
months["04"] = months["06"] = months["09"] = months["11"] = "30";
map<string, long long int> m;
string s;
cin >> s;
for (long long int i = 6; i < s.length() - 3; i++) {
if (s.substr(i, 3) == "201") {
if (s[i + 3] == '3' || s[i + 3] == '4' || s[i + 3] == '5') {
if (s[i - 1] == '-' && s[i - 4] == '-' && s[i - 6] != '-' &&
s[i - 5] != '-' && s[i - 3] != '-' && s[i - 2] != '-') {
if (s.substr(i - 3, 2) >= "01" && s.substr(i - 3, 2) <= "12") {
string sub = s.substr(i - 3, 2);
string day = s.substr(i - 6, 2);
if (day >= "01" && day <= months[sub]) {
if (m.count(s.substr(i - 6, 10)) == 0)
m[s.substr(i - 6, 10)] = 1;
else
m[s.substr(i - 6, 10)] += 1;
}
}
}
}
}
}
long long int mx = 0;
string ans;
for (auto i : m) {
if (i.second > mx) {
mx = i.second;
ans = i.first;
}
}
cout << ans << "\n";
}
return 0;
}
| 8 |
CPP
|
def get_days(mon):
if mon == '02':
return '28'
elif mon == '01' or mon == '03' or mon == '05' or mon == '07' or mon == '08' or mon == '10' or mon == '12':
return '31'
else:
return '30'
def main():
s = str(input())
d = {}
for i in range(len(s)-9):
if s[i:i+10] not in d:
d[s[i:i+10]] = 1
else:
d[s[i:i+10]] += 1
d1 = {}
digs = '0123456789'
for (key,value) in d.items():
if key[2] == key[5] and key[2] == '-':
if key[6:9] == '201':
if '3' <= key[9] <= '5' :
if (key[0] in digs) and (key[1] in digs) and (key[3] in digs) and (key[4] in digs):
d1[key] = value
d2 = {}
for (key,value) in d1.items():
if 1 <= int(key[3:5]) <= 12:
if 1 <= int(key[0:2]) <= int(get_days(key[3:5])):
d2[key] = value;
ans = 0
ans_str = ''
for (key,value) in d2.items():
#print(key + " : " + str(value))
if value > ans:
ans = value
ans_str = key
print(ans_str)
return
main()
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
long long power(long long b, long long e, long long m) {
if (e == 0) return 1;
if (e % 2)
return b * power(b * b % m, (e - 1) / 2, m) % m;
else
return power(b * b % m, e / 2, m);
}
long long power(long long b, long long e) {
if (e == 0) return 1;
if (e % 2)
return b * power(b * b, (e - 1) / 2);
else
return power(b * b, e / 2);
}
bool id(char c) { return (c >= 48 && c <= 57); }
bool check(string s) {
bool t = true;
if (s[2] != '-' || s[5] != '-') t = false;
if (!t) return t;
if (!id(s[0]) || !id(s[1]) || !id(s[3]) || !id(s[4]) || !id(s[6]) ||
!id(s[7]) || !id(s[8]) || !id(s[9]))
t = false;
if (!t) return t;
string dd, mm, yyyy;
dd = s.substr(0, 2);
mm = s.substr(3, 2);
yyyy = s.substr(6, 4);
int d = stoi(dd);
int m = stoi(mm);
int y = stoi(yyyy);
if (d <= 0) return false;
if (y < 2013 || y > 2015) t = false;
if (!t) return t;
if (m == 2 && d <= 28)
return true;
else if (m == 2)
return false;
if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12) {
if (d <= 31)
return true;
else
return false;
} else {
if (d <= 30)
return true;
else
return false;
}
}
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s, k;
cin >> s;
long long l = s.length(), count;
map<string, long long> m;
for (auto i = 0; i <= l - 10; i++) {
k = s.substr(i, 10);
if (check(k)) m[k]++;
}
k = m.begin()->first;
count = m.begin()->second;
auto j = m.begin();
j++;
while (j != m.end()) {
if (j->second > count) {
count = j->second;
k = j->first;
}
j++;
}
cout << k;
return 0;
}
| 8 |
CPP
|
import re
s = input()
# print(re.findall("(?=(\d\d\d))", s))
x = re.findall("(?=(\d\d-\d\d-\d\d\d\d))", s)
# print(x)
ans = ""
# print(x)
# input()
# print(x.split('-'))
# input()
date_count = {}
max_count = 0
for date in x:
d, m, y = [int(x) for x in date.split('-')]
if(2013 <= y <= 2015 and 1 <= d <= 31 and 1 <= m <= 12):
if m in [1, 3, 5, 7, 8, 10, 12] and 1 <= d <= 31:
try:
date_count[date] += 1
except KeyError:
date_count[date] = 1
elif m == 2 and 1 <= d <= 28:
try:
date_count[date] += 1
except KeyError:
date_count[date] = 1
elif m in [4, 6, 9, 11] and 1 <= d <= 30:
try:
date_count[date] += 1
except KeyError:
date_count[date] = 1
if date in date_count and date_count[date] > max_count:
max_count = date_count[date]
ans = date
else:
pass
# print(x)
# print(date_count)
print(ans)
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
string s;
int cnt[2016][13][32], Max, ansY, ansM, ansD;
int main() {
getline(cin, s);
Max = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] >= '0' && s[i] <= '9') {
int d = s[i] - '0';
if (s[i + 1] >= '0' && s[i + 1] <= '9') {
d = d * 10 + (s[i + 1] - '0');
if (d == 0 || d > 31) continue;
if (s[i + 2] == '-') {
if (s[i + 3] >= '0' && s[i + 3] <= '9') {
int m = s[i + 3] - '0';
if (s[i + 4] >= '0' && s[i + 4] <= '9') {
m = m * 10 + (s[i + 4] - '0');
if (m == 0 || m > 12) continue;
if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 ||
m == 12) {
if (d > 31) continue;
} else if (m == 2) {
if (d > 28) continue;
} else {
if (d > 30) continue;
}
if (s[i + 5] == '-') {
if (s[i + 6] == '2') {
if (s[i + 7] == '0') {
if (s[i + 8] == '1') {
if (s[i + 9] >= '3' && s[i + 9] <= '5') {
int y = 2010 + (s[i + 9] - '0');
cnt[y][m][d]++;
if (cnt[y][m][d] > Max) {
Max = cnt[y][m][d];
ansY = y;
ansM = m;
ansD = d;
}
}
}
}
}
}
}
}
}
}
}
}
if (ansD >= 10) {
printf("%d", ansD);
} else {
printf("0%d", ansD);
}
printf("-");
if (ansM >= 10) {
printf("%d", ansM);
} else {
printf("0%d", ansM);
}
printf("-");
printf("%d\n", ansY);
return 0;
}
| 8 |
CPP
|
try:
import re
st = input()
dct = {}
r = re.compile(r'(\d\d-\d\d-\d\d\d\d)')
r2 = re.compile(r'(\d\d)-(\d\d)-(\d\d\d\d)')
def judge_date(date):
rst = r2.match(date)
d, m, y = map(int, rst.groups())
if 2013 <= y <= 2015:
if 1 <= m <= 12:
if m in (1, 3, 5, 7, 8, 10, 12):
if d > 31:
return False
elif m == 2:
if d > 28:
return False
else:
if d > 30:
return False
if d <= 0:
return False
return True
return False
while st:
rst = r.search(st)
if rst is None:
break
awd = rst.group()
if judge_date(awd):
try:
dct[awd] += 1
except KeyError:
dct[awd] = 1
st = st[rst.start() + 1:]
print(max(dct.items(), key=lambda x: x[1])[0])
except Exception as e:
print(e)
| 8 |
PYTHON3
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
const int d[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int t, n;
string s;
map<int, int> red;
void output(int idx, int a[]) {
for (int i = 0; i <= idx; i++) cout << a[i] << endl;
}
void work() {
red.clear();
int idx = 0;
string res[maxn], a = "";
for (int i = 0; i < s.length(); i++) {
if (s[i] == '-') {
res[idx++] = a;
a = "";
} else {
a.push_back(s[i]);
}
}
res[idx] = a;
for (int i = idx; i >= 2; i--) {
if (res[i].length() >= 4) {
int tmp = (res[i][0] - '0') * 1000 + (res[i][1] - '0') * 100 +
(res[i][2] - '0') * 10 + (res[i][3] - '0');
if (tmp >= 2013 && tmp <= 2015) {
int dd = tmp * 10000;
if (res[i - 1].length() == 2) {
tmp = (res[i - 1][0] - '0') * 10 + (res[i - 1][1] - '0');
if (tmp > 0 && tmp <= 12) {
dd += tmp * 100;
if (res[i - 2].length() >= 2) {
int mm = tmp;
tmp = (res[i - 2][res[i - 2].length() - 2] - '0') * 10 +
(res[i - 2][res[i - 2].length() - 1] - '0');
if (tmp > 0 && tmp <= d[mm]) {
dd += tmp;
red[dd]++;
}
}
}
}
}
}
}
int amt = 0, ans;
for (map<int, int>::iterator it = red.begin(); it != red.end(); it++) {
if (it->second >= amt) {
amt = it->second;
ans = it->first;
}
}
for (int i = 0; i < 2; i++) {
if (ans % 100 < 10)
cout << "0" << ans % 100 << "-";
else
cout << ans % 100 << "-";
ans /= 100;
}
cout << ans << endl;
}
int main() {
ios::sync_with_stdio(false);
while (cin >> s) work();
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
int month[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int check(string s) {
if (s[2] != '-' || s[5] != '-') return 0;
for (int i = 0; i < 10; i++)
if (i != 2 && i != 5)
if (s[i] == '-') return 0;
int mm = stoi(s.substr(3, 2));
int dd = stoi(s.substr(0, 2));
int yyyy = stoi(s.substr(6, 4));
if (yyyy < 2013 || yyyy > 2015) return 0;
if (mm == 0 || mm > 12) return 0;
if (dd == 0 || dd > month[mm - 1]) return 0;
return 1;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
string s;
cin >> s;
int n = s.size();
map<string, int> mapper;
string best;
for (int i = 0; i + 9 < n; i++) {
string curr = s.substr(i, 10);
if (check(curr)) mapper[curr]++;
if (mapper[curr] > mapper[best]) best = curr;
}
cout << best << '\n';
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
int ans[2050][15][50];
int data[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool judge(int d, int m, int y) {
if (y <= 2015 && y >= 2013) {
if (m >= 1 && m <= 12) {
if (d >= 1 && d <= data[m - 1]) return true;
}
}
return false;
}
const int N = 1e5 + 100;
char st[N];
int getnex(int x, int n, int &len) {
int now = 0;
len = 0;
for (int i = x; i < n; i++) {
if (st[i] == '-') break;
now *= 10;
now += st[i] - '0';
len++;
if (len == 4) return now;
}
return now;
}
vector<int> G;
int main() {
scanf("%s", st);
int len = strlen(st);
for (int i = 0; i < len; i++) {
if (st[i] == '-') G.push_back(i);
}
for (int i = 0; i < len; i++) {
if (st[i] == '-') continue;
int l;
int d = getnex(i, len, l);
if (l != 2) d = 100;
int now = upper_bound(G.begin(), G.end(), i) - G.begin();
if (now == G.size()) continue;
int m = getnex(G[now] + 1, len, l);
if (l != 2) m = 100;
now = upper_bound(G.begin(), G.end(), G[now]) - G.begin();
if (now == G.size()) continue;
int y = getnex(G[now] + 1, len, l);
if (l != 4) y = 0;
if (judge(d, m, y)) {
ans[y][m][d]++;
}
}
int mx = 0;
int dd = 0, mm = 0, yy = 0;
for (int i = 2013; i <= 2015; i++) {
for (int j = 1; j <= 12; j++) {
for (int k = 1; k <= 31; k++) {
if (ans[i][j][k] > mx) {
mx = ans[i][j][k];
yy = i, mm = j, dd = k;
}
}
}
}
printf("%02d-%02d-%d\n", dd, mm, yy);
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
char s[100010];
int mon[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int anum;
map<string, int> ms;
bool isnum(char a) { return a >= '0' && a <= '9'; }
int main() {
while (~scanf("%s", s)) {
ms.clear();
anum = 0;
int tmp = 0;
string tt;
int max = 0;
for (int i = 0; s[i + 9] != 0; i++) {
if (isnum(s[i]) && isnum(s[i + 1]) && !isnum(s[i + 2]) &&
isnum(s[i + 3]) && isnum(s[i + 4]) && !isnum(s[i + 5]) &&
isnum(s[i + 6]) && isnum(s[i + 7]) && isnum(s[i + 8]) &&
isnum(s[i + 9])) {
int a0 = atoi(s + i), a1 = atoi(s + i + 3), a2;
char ttt = s[i + 10];
s[i + 10] = 0;
a2 = atoi(s + i + 6);
s[i + 10] = ttt;
if (a2 <= 2015 && a2 >= 2013 && a1 <= 12 && a1 >= 1 && a0 > 0 &&
a0 <= mon[a1]) {
ms[string(s + i, s + i + 10)]++;
if (ms[string(s + i, s + i + 10)] > max) {
tt = string(s + i, s + i + 10);
max = ms[tt];
}
}
}
}
printf("%s", tt.c_str());
puts("");
}
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
const int d[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
string ans[1000010];
int a[40000000], b[1000000];
int main() {
string str;
int ma = 0, tot = 0, t = 0, an = 0;
cin.tie(0);
cin >> str;
for (int i = 2; i < str.length() - 6; ++i)
if (str[i] == '-' && str[i + 3] == '-' && str[i - 1] != '-' &&
str[i + 1] != '-' && str[i + 7] != '-' && str[i + 2] != '-' &&
str[i - 2] != '-') {
tot++;
for (int j = i - 2; j <= i + 7; ++j) ans[tot] += str[j];
}
for (int i = 1; i <= tot; ++i) {
int sum1, sum2, sum3;
sum1 = (ans[i][0] - '0') * 10 + (ans[i][1] - '0');
sum2 = (ans[i][3] - '0') * 10 + (ans[i][4] - '0');
sum3 = (ans[i][6] - '0') * 1000 + (ans[i][7] - '0') * 100 +
(ans[i][8] - '0') * 10 + (ans[i][9] - '0');
if (sum1 > d[sum2]) continue;
if (sum3 < 2013 || sum3 > 2015) continue;
if (sum1 <= 0) continue;
a[sum3 * 10000 + sum2 * 100 + sum1]++;
b[++t] = sum3 * 10000 + sum2 * 100 + sum1;
}
for (int i = 1; i <= t; ++i) {
if (a[b[i]] > ma) ma = a[b[i]], an = b[i];
}
if (an % 100 < 10)
cout << 0 << an % 100 << '-';
else
cout << an % 100 << '-';
if (an / 100 % 100 < 10)
cout << 0 << an / 100 % 100 << '-';
else
cout << an / 100 % 100 << '-';
cout << an / 10000;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
const int day[15] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int n = 0, y, m, d, j;
string str, v, x;
int main() {
cin >> str;
for (int i = 0; i + 10 <= str.length(); i++) {
x = str.substr(i, 10);
if (sscanf((x + "#1").c_str(), "%2d-%2d-%4d#%d", &d, &m, &y, &j) != 4)
continue;
if (j != 1 || y < 2013 || y > 2015 || m < 1 || m > 12 || d < 1 ||
d > day[m])
continue;
mp[x]++;
if (n < mp[x]) n = mp[x], v = x;
}
cout << v << endl;
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
int days[13] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool validity(string s) {
for (int i = 0; i < 10; i++) {
if (i == 2 || i == 5) {
if (s[i] == '-')
continue;
else
return false;
}
if (s[i] >= '0' && s[i] <= '9')
continue;
else
return false;
}
int d = (s[0] - '0') * 10 + (s[1] - '0');
int m = (s[3] - '0') * 10 + (s[4] - '0');
int y = (s[6] - '0') * 1000 + (s[7] - '0') * 100 + (s[8] - '0') * 10 +
(s[9] - '0');
if (y < 2013 || y > 2015) return false;
if (m < 1 || m > 12) return false;
if (d < 1 || d > days[m]) return false;
return true;
}
int main() {
map<string, int> m;
map<string, int>::iterator it;
int max = 0;
string s, tmp, proph;
cin >> s;
int len = s.length();
for (int i = 0; i + 10 <= len; i++) {
tmp = s.substr(i, 10);
bool f = validity(tmp);
if (f) {
it = m.find(tmp);
if (it == m.end()) {
m.insert(make_pair(tmp, 1));
if (max == 0) {
max = 1;
proph = tmp;
}
} else {
int f = it->second;
f++;
if (f > max) {
max = f;
proph = tmp;
}
m.erase(it);
m.insert(make_pair(tmp, f));
}
}
}
cout << proph << endl;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int to_int(string s) {
stringstream ss;
if (s.find('-') != -1) return 0;
ss << s;
int r = 0;
ss >> r;
return r;
}
bool check(string s) {
if (s.length() != 10 || s[2] != '-' || s[5] != '-') return false;
int d = to_int(s.substr(0, 2));
int m = to_int(s.substr(3, 2));
int y = to_int(s.substr(6, 4));
if (y < 2013 || y > 2015 || m < 1 || m > 12 || d < 1 || d > days[m - 1])
return false;
return true;
}
int main() {
ios_base::sync_with_stdio(false);
string s;
cin >> s;
map<string, int> m;
for (int i = 0; i < s.size() - 9; i++) {
string sub = s.substr(i, 10);
if (!check(sub)) continue;
if (m.count(sub))
m.find(sub)->second++;
else
m.insert(pair<string, int>(sub, 1));
}
pair<string, int> ans = *m.begin();
for (map<string, int>::iterator it = m.begin(); it != m.end(); it++)
if (it->second > ans.second) ans = *it;
cout << ans.first << endl;
return 0;
}
| 8 |
CPP
|
#include <bits/stdc++.h>
using namespace std;
long long int checkyear(char ch1, char ch2, char ch3, char ch4) {
if (ch1 == '2' && ch2 == '0' && ch3 == '1' &&
(ch4 == '3' || ch4 == '4' || ch4 == '5'))
return 1;
else
return 0;
}
long long int checkmonth(char ch1, char ch2) {
if (ch1 == '0' && ch2 == '2')
return 1;
else if (ch1 == '0' &&
(ch2 == '1' || ch2 == '3' || ch2 == '5' || ch2 == '7' || ch2 == '8'))
return 3;
else if ((ch1 == '1') && (ch2 == '0' || ch2 == '2'))
return 3;
else if ((ch1 == '0') && (ch2 == '4' || ch2 == '6' || ch2 == '9'))
return 2;
else if (ch1 == '1' && ch2 == '1')
return 2;
else
return 0;
}
long long int checkday(char ch1, char ch2, long long int month) {
if (month == 1) {
if ((ch1 == '0') &&
(ch2 == '1' || ch2 == '2' || ch2 == '3' || ch2 == '4' || ch2 == '5' ||
ch2 == '6' || ch2 == '7' || ch2 == '8' || ch2 == '9'))
return 1;
else if ((ch1 == '1') &&
(ch2 == '0' || ch2 == '1' || ch2 == '2' || ch2 == '3' ||
ch2 == '4' || ch2 == '5' || ch2 == '6' || ch2 == '7' ||
ch2 == '8' || ch2 == '9'))
return 1;
else if ((ch1 == '2') && (ch2 == '0' || ch2 == '1' || ch2 == '2' ||
ch2 == '3' || ch2 == '4' || ch2 == '5' ||
ch2 == '6' || ch2 == '7' || ch2 == '8'))
return 1;
else
return 0;
} else if (month == 2) {
if ((ch1 == '0') &&
(ch2 == '1' || ch2 == '2' || ch2 == '3' || ch2 == '4' || ch2 == '5' ||
ch2 == '6' || ch2 == '7' || ch2 == '8' || ch2 == '9')) {
return 1;
} else if ((ch1 == '1') &&
(ch2 == '0' || ch2 == '1' || ch2 == '2' || ch2 == '3' ||
ch2 == '4' || ch2 == '5' || ch2 == '6' || ch2 == '7' ||
ch2 == '8' || ch2 == '9')) {
return 1;
} else if ((ch1 == '2') &&
(ch2 == '0' || ch2 == '1' || ch2 == '2' || ch2 == '3' ||
ch2 == '4' || ch2 == '5' || ch2 == '6' || ch2 == '7' ||
ch2 == '8' || ch2 == '9')) {
return 1;
} else if ((ch1 == '3') && (ch2 == '0')) {
return 1;
} else
return 0;
} else if (month == 3) {
if ((ch1 == '0') &&
(ch2 == '1' || ch2 == '2' || ch2 == '3' || ch2 == '4' || ch2 == '5' ||
ch2 == '6' || ch2 == '7' || ch2 == '8' || ch2 == '9')) {
return 1;
} else if ((ch1 == '1') &&
(ch2 == '0' || ch2 == '1' || ch2 == '2' || ch2 == '3' ||
ch2 == '4' || ch2 == '5' || ch2 == '6' || ch2 == '7' ||
ch2 == '8' || ch2 == '9')) {
return 1;
} else if ((ch1 == '2') &&
(ch2 == '0' || ch2 == '1' || ch2 == '2' || ch2 == '3' ||
ch2 == '4' || ch2 == '5' || ch2 == '6' || ch2 == '7' ||
ch2 == '8' || ch2 == '9')) {
return 1;
} else if ((ch1 == '3') && (ch2 == '0' || ch2 == '1')) {
return 1;
} else
return 0;
}
}
int main() {
char a[100003], b[1000];
string s;
scanf("%s", a);
map<string, long long int> m;
map<string, long long int>::iterator it, pos;
long long int len, i = 0, c, d, j = 0, year, month, day;
len = strlen(a);
for (i = 0; i <= (len - 10); i++) {
j = 0;
year = checkyear(a[i + 6], a[i + 7], a[i + 8], a[i + 9]);
if (year) {
month = checkmonth(a[i + 3], a[i + 4]);
if (month) {
day = checkday(a[i], a[i + 1], month);
if (day && a[i + 2] == '-' && a[i + 5] == '-') {
b[0] = a[i];
b[1] = a[i + 1];
b[2] = a[i + 2];
b[3] = a[i + 3];
b[4] = a[i + 4];
b[5] = a[i + 5];
b[6] = a[i + 6];
b[7] = a[i + 7];
b[8] = a[i + 8];
b[9] = a[i + 9];
b[10] = '\0';
s = b;
m[s]++;
}
}
}
}
long long int max = 0;
it = m.begin();
for (; it != m.end(); it++) {
if ((it->second) > max) {
max = it->second;
pos = it;
}
}
cout << pos->first;
return 0;
}
| 8 |
CPP
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.