-
Notifications
You must be signed in to change notification settings - Fork 2
/
CF103C.cpp
79 lines (73 loc) · 1.19 KB
/
CF103C.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
ID: mfs6174
email: [email protected]
PROG: ti
LANG: C++
*/
#include<iostream>
#include<fstream>
#include<string>
#include<sstream>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<deque>
#include<iomanip>
#include<cmath>
#include<set>
#define sf scanf
#define pf printf
#define llg long long
using namespace std;
//ifstream inf("ti.in");
//ofstream ouf("ti.out");
//freopen("ti.in","r",stdin);
const int maxlongint=2147483647;
int i,j,k,t,n,m,mm;
int ff[110000][30];
int shu[30];
char s[110000],ss[110000];
int main()
{
sf("%s%s",s,ss);
m=strlen(ss);
n=strlen(s);
if (m>n)
{
cout<<0<<endl;
exit(0);
}
for (i=1;i<=n;i++)
{
for (j=0;j<=26;j++)
ff[i][j]=ff[i-1][j];
if (s[i-1]=='?')
ff[i][0]++;
else
ff[i][s[i-1]-'a'+1]++;
}
for (i=1;i<=m;i++)
shu[ss[i-1]-'a'+1]++;
i=1;
while (i+m-1<=n)
{
t=i+m-1;
k=0;
bool can=true;
for (j=1;j<=26;j++)
if (shu[j]<(ff[t][j]-ff[i-1][j]))
{
can=false;
break;
}
else
k+=shu[j]-(ff[t][j]-ff[i-1][j]);
if (can&&(k==(ff[t][0]-ff[i-1][0])))
mm++;
i++;
}
cout<<mm<<endl;
return 0;
}