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 |
Re:贴一下我的代码 (16MS)In Reply To:贴一下我的代码 (16MS) Posted by:sjb358714 at 2009-08-21 10:35:20 > #include "stdio.h" > #include "string.h" > #define N 61 > > int main() > { > int m, nCases, i, j, k, flg; > char maxL, base[10][N], suq[N], fsuq[N]; > scanf("%d", &nCases); > while (nCases--) { > scanf("%d", &m); > for (i = 0; i < m; i++) > scanf("%s", base[i]); > maxL = 0; > for (i = 0; i < N - 3; i++) { > for (j = 3; j < N - i; j++) { > strncpy(suq, base[0] + i, j); > suq[j] = '\0'; > flg = 1; > for (k = 1; k < m; k++) { > if (strstr(base[k], suq) == NULL) { > flg = 0; > break; > } > } > if (flg && j > maxL) { > maxL = j; > strcpy(fsuq, suq); > } > else if (flg && j == maxL) > if (strcmp(suq, fsuq) < 0) > strcpy(fsuq, suq); > } > } > if (maxL == 0) printf("no significant commonalities\n"); > else printf("%s\n", fsuq); > } > return 0; > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator