B - Longest Prefix
很水的一道题,结果自己没有读懂题,就是求a和b的最大可能前缀,b可以随意更改字母位置
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
char a[N],b[N]; //两个字符
vector<int>num; //存放b中的每个字母数量
typedef long long LL;
int main()
{
std::ios::sync_with_stdio(false);
int T;
cin>>T;
while(T--)
{
num.clear();
cin>>a>>b;
int n=strlen(b);
for(int i=0; i<26; i++)
num.push_back(0);
for(int i=0; i<n; i++)
{
num[b[i]-'a']++;
}
n=strlen(a);
int i;
for(i=0; i<n; i++)
{
int t=a[i]-'a';
if(num[t]>0)
num[t]--;
else if(num[t]==0)
break;
}
cout<<i<<endl;
}
}