Description
Input
Output
Sample Input
3 TAC
5 CATCH
Sample Output
HINT
提示:100%的數據中,N<=50.
50%的數據中,N<=20.
最後勒,就輸出最小的代價就好了
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n[5],d=6;
char s[5][51];
int change(int x,int y)
{
int p=1,q=1;
while(p>0 && p<=n[x] && p<=n[y] && s[x][p]==s[y][p]) p++;
p--;
while(q>0 && q<=p && q<=n[d-x-y] && s[x][q]==s[d-x-y][q]) q++;
q--;
return n[x]-p + n[y]-p + n[d-x-y]-q + p-q;
}
int main()
{
int n1,n2,n3;
scanf("%d%s%d%s%d%s",&n[1],s[1]+1,&n[2],s[2]+1,&n[3],s[3]+1);
int ans=999999999;
ans=min(ans,change(1,2));
ans=min(ans,change(1,3));
ans=min(ans,change(2,3));
printf("%d\n",ans);
return 0;
}