Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
直接暴力#include<cstdio> #include<cstring> #include<algorithm> using namespace std; char s[105][105]; int n; int solve() { char sub[105]; char rsub[105]; int len=strlen(s[0]); int cnt=0; for(int l=len;l>0;l--) { for(int x=0;x+l<=len;x++) { memset(sub,0,sizeof(sub)); memset(rsub,0,sizeof(rsub)); strncpy(sub,s[0]+x,l); strcpy(rsub,sub); reverse(rsub,rsub+strlen(rsub)); cnt=0; for(int i=1;i<n;i++) { if(strstr(s[i],sub)!=NULL||strstr(s[i],rsub)!=NULL) { cnt++; } else break; } if(cnt==n-1) return strlen(sub); } } return 0; } int main() { int cas; scanf("%d",&cas); while(cas--) { scanf("%d",&n); memset(s,0,sizeof(s)); for(int i=0;i<n;i++) { scanf("%s",s[i]); } printf("%d\n",solve()); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator