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<stdio.h> #include<string.h> int main() { char s[15][65],temp[65],ans[30][65]; int t,n; scanf("%d", &t); while(t--) { scanf("%d", &n); for(int i = 1; i <= n; ++i) scanf("%s", s[i]); memset(ans, 0, sizeof(ans)); int flag = 0; for(int j,l = 60; l > 2; --l) { for(int i = 0; i <= 60-l; ++i) { memset(temp, 0, sizeof(temp)); strncpy(temp, s[1]+i, l); for(j = 2; j <= n; ++j) if(!strstr(s[j], temp))break; if(j > n) strcpy(ans[++flag], temp); } if(flag) { memset(temp, 0, sizeof(temp)); strcpy(temp, ans[1]); for(int i = 2; i <= flag; ++i) if(strcmp(ans[i], temp) < 0) strcpy(temp, ans[i]); printf("%s\n", temp); break; } } if(!flag)printf("no significant commonalities\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator