题意:
输入三个字符串,问你存在着三个字符串子串的字符串的最短长度。
POINT:
枚举A(3,3)种可能。
特殊情况若字符串包含,则处理一下。
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
using namespace std;
const int maxn = 1e5+55;
#define LL long long
int nxt[maxn];
void prenxt(string s)
{
int i=0,j;
nxt[0]=j=-1;
while(i<s.length()){
while(j!=-1&&s[j]!=s[i]) j=nxt[j];
nxt[++i]=++j;
}
}
int kmp(string s1,string s2)
{
prenxt(s2);
int i=0,j=0;
while(i<s1.length()){
while(j!=-1&&s1[i]!=s2[j]) j=nxt[j];
i++,j++;
if(j==s2.length()) return (int)s2.length();
}
return j;
}
int ans=0x3f3f3f3f;
void doit(string s1, string s2,string s3)
{
int len=kmp(s1,s2);
string s="";
s+=s1;
for(int i=len;i<s2.length();i++){
s+=s2[i];
}
len=kmp(s,s3);
ans=min(ans,(int)(s.length()-len+s3.length()));
}
int main()
{
string s1,s2,s3;
cin>>s1>>s2>>s3;
doit(s1,s2,s3);
doit(s1,s3,s2);
doit(s2,s1,s3);
doit(s3,s1,s2);
doit(s2,s3,s1);
doit(s3,s2,s1);
printf("%d\n",ans);
}