二、短语 给定一个文本文件作为输入,插在其中最长的重复子字符串。例如,“Ask not what your country can do for you, but what you can do for your country”中最长的重复字符串是“can do for you”,第二长的是“your country”。 方法一:双重for循环依次比较每个字符串,找到最长重复子字符串
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
//找到两个字符串公共部分的长度
int comlen(char *p, char *q)
{
int i = 0;
while(*p &&(*p++==*q++))
{
i++;
}
return i;
}
int main()
{
int i, j;
int maxi, maxj;
int currentlen, maxlen =-1;
char *str ="ask not what your country can do for you, but what you can do for your country";