标签:char queue using lang ati string 注意 class cte
Input
Output
Sample Input
abcd aaaa ababab .
Sample Output
1 4 3
Hint
#include<map> #include<set> #include<cmath> #include<queue> #include<stack> #include<vector> #include<cstdio> #include<iomanip> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define pi acos(-1) #define ll long long #define mod 1000000007 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 using namespace std; const double g=10.0,eps=1e-9; const int N=1000000+5,maxn=1000000+5,inf=0x3f3f3f3f; int Next[N],slen; string str; void getnext() { int k=-1; Next[0]=-1; for(int i=1;i<slen;i++) { while(k>-1&&str[k+1]!=str[i])k=Next[k]; if(str[k+1]==str[i])k++; Next[i]=k; } } int main() { ios::sync_with_stdio(false); cin.tie(0); // cout<<setiosflags(ios::fixed)<<setprecision(2); while(cin>>str){ if(str==".")break; slen=str.size(); getnext(); int ans=slen-Next[slen-1]-1; if(slen%ans)cout<<1<<endl; else cout<<slen/ans<<endl; } return 0; }
标签:char queue using lang ati string 注意 class cte
原文地址:http://www.cnblogs.com/acjiumeng/p/6809695.html