Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

贴一下我的代码 (16MS)

Posted by sjb358714 at 2009-08-21 10:35:20 on Problem 3080
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator