标题:求字串,求注释
只看楼主
yausgw
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2015-8-30
结帖率:0
 问题点数:0 回复次数:0 
求字串,求注释
#include<stdio.h>
#include<string.h>

int t,n;
char str[100][101];

int searchMaxSubString(char *source){
    int subStrLen=strlen(source),sourceStrLen=strlen(source);
    int i,j;
    bool foundMaxSubstr;
    char subStr[101],revSubStr[101];

    while(subStrLen>0){  //搜索不同长度的子串,从最长的子串开始搜索
        for(i=0;i<=sourceStrLen-subStrLen;i++){
            //搜素长度为subStrlen的全部子串
            strncpy(subStr,source+i,subStrLen);
            strncpy(revSubStr,source+i,subStrLen);
            subStr[subStrLen]=revSubStr[subStrLen]='\0';
            strrev(revSubStr);
            foundMaxSubstr=true;
            for(j=0;j<n;j++)
                if(strstr(str[j],subStr)==NULL&&strstr(str[j],revSubStr)==NULL){
                    foundMaxSubstr=false;
                    break;
                }
                if(foundMaxSubstr)
                    return(subStrLen);
        }
        subStrLen--;
    }

    return(0);
}

void main()
{
    int i,minStrLen,subStrLen;
    char minStr[101];

    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        minStrLen=100;
        for(i=0;i<n;i++){    //输入一组字符串
            scanf("%s",str[i]);
            if(strlen(str[i])<minStrLen){    //寻找输入字符串中的最短字符
                strcpy(minStr,str[i]);
                minStrLen=strlen(minStr);
            }
        }
        subStrLen=searchMaxSubString(minStr);//搜索满足条件的最长字符串
        printf("%d\n",subStrLen);
    }
}
搜索更多相关主题的帖子: include source 
2016-04-06 10:00



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-463304-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013583 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved