#include<bits/stdc++.h> #define INF 0x3f3f3f3f #define maxn 10000010 typedeflonglong ll; usingnamespacestd; #define rep(i, n, args...) for (ll i = 0, ##args; i < n; i++) #define repr(i, s, e, args...) for (ll i = s, ##args; i < e; i++) #define erg(i, u, args...) for (ll i = vtx[u], ##args; ~i; i = eg[i].nxt) #define fulset(x, v) memset(x, v, sizeof(x)); constint N = 200010; int exnxt[N]; int extend[2*N]; int nxt[N]; char S[N]; char T[N]; voidgetNext(){ int j,k; int tlen = strlen(T); j=0; k=-1; nxt[0]=-1; while(j<=tlen){ if(k==-1||T[j]==T[k]) nxt[++j]=++k; else k=nxt[k]; } } voidex_GetNext() { int m = strlen(T); int a = 0, p = 0; exnxt[0] = m; for (int i = 1; i < m; i++) { if (i >= p || i + exnxt[i - a] >= p) { if (i >= p) p = i; while (p < m && T[p] == T[p - i]) p++; exnxt[i] = p - i; a = i; } else exnxt[i] = exnxt[i - a]; } }
/* 求解 extend[] */ voidGetExtend() { int a = 0, p = 0; int n = strlen(S); int m = strlen(T); ex_GetNext(); for (int i = 0; i < n; i++) { if (i >= p || i + exnxt[i - a] >= p) // i >= p 的作用:举个典型例子,S 和 T 无一字符相同 { if (i >= p) p = i;
while (p < n && p - i < m && S[p] == T[p - i]) p++; extend[i] = p - i; a = i; } else extend[i] = exnxt[i - a]; } }
intmain() { int t; scanf("%d",&t); int co=0; while (t--) { co++; int lar = 0,eq = 0, sma = 0; scanf("%s",T); int lent = strlen(T); rep(i, lent) { S[i] = T[i]; S[i+lent] = T[i]; } getNext(); int to_div; if (nxt[lent] != 0 && lent % (lent-nxt[lent]) == 0) to_div = lent / (lent-nxt[lent]); else to_div = 1; ex_GetNext(); GetExtend(); rep(i,lent) { if (extend[i] >= lent) eq ++; elseif (S[i+extend[i]] > T[extend[i]]) lar ++; else sma ++; } printf("Case %d: %d %d %d\n",co,sma/to_div,eq/to_div,lar/to_div); } return0; }