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

暴力枚举子串,附拙劣代码

Posted by Ren_Bocheng at 2015-08-16 13:33:09 on Problem 3080
#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:
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