CodeForces 625B War of the Corporations

时间:2021-04-13 08:44:12

暴力匹配+一点判断

#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <queue>
#include <stack>
#include <map>
#include <vector>
using namespace std; const int maxn=+;
char s[maxn];
char t[];
struct Seg
{
int l,r;
Seg(int a,int b){l=a;r=b;}
};
vector<Seg>v;
int L,R; bool CMP(int pos)
{
bool flag=; for(int i=;t[i];i++)
{
if(t[i]!=s[i+pos]) {flag=;break;}
}
return flag;
} int main()
{
scanf("%s",s);
scanf("%s",t);
v.clear(); int lens=strlen(s);
int lent=strlen(t); for(int i=;i<lens;i++)
{
if(CMP(i))
{
Seg seg(i,i+lent-);
v.push_back(seg);
}
}
int ans;
if(v.size()==) ans=;
else
{
ans=;
L=v[].l,R=v[].r;
for(int i=;i<v.size();i++)
{
if(v[i].l<=R) L=v[i].l;
else
{
ans++;
L=v[i].l;
R=v[i].r;
}
}
}
printf("%d\n",ans);
return ;
}