题意就是我们通过几次删头或尾的操作,看看两个字符串能不能变成一样的
经过观察我们发现,因为我们只能去头去尾,所以本质上剩下的就是他们的公共子串
因为他问的是至少删除多少个数才能获得这个答案,所以反过来就是问,两个字符串的公共子串最长是多少
匹配好之后删除的个数就是其他的字符了,就是 l a − a n s − l b − a n s la - ans - lb - ans la−ans−lb−ans
数据范围也不大,暴力统计一下就行(注:好好复习暴力算法
// Problem: C. Double-ended Strings
// Contest: Codeforces - Codeforces Round #710 (Div. 3)
// URL: https://codeforces.com/problemset/problem/1506/C
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// Code by: ING__
//
// Powered by CP Editor (https://cpeditor.org)
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#define ll long long
#define re return
using namespace std;
typedef pair<int, int> PII;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,1,0,-1};
int T;
int main(){
cin >> T;
while(T--){
char a[30];
char b[30];
scanf("%s", a + 1);
scanf("%s", b + 1);
int la = strlen(a + 1);
int lb = strlen(b + 1);
// 求一个最长在b中的子串的长度是多少
int ans = 0;
for(int x = 1; x <= la; x++){
for(int y = 1; y <= lb; y++){
if(a[x] == b[y]){
int cnt = 1;
for(int i = 1; i + x <= la && i + y <= lb; i++){
if(a[x + i] == b[y + i]){
cnt++;
}
else{
break;
}
}
ans = max(ans, cnt);
}
}
}
cout << la + lb - 2 * ans << endl;
}
}