

Hãy luôn nhớ cảm ơn và vote 5*
nếu câu trả lời hữu ích nhé!
#include<bits/stdc++.h>
using namespace std;
string s, s1, s2, s3; int n,m, i, k, res, d;
map<char, int> m2; map<char, int> m1;
int main()
{
cin >> n >> m;
cin >> s1 >> s2;
for(i = 0; i < n; i++) m1[s1[i]]++;
for(i = 0; i < n; i++)
{
m2[s2[i]]++;
if(m1[s2[i]]>=1&& m2[s2[i]] <= m1[s2[i]])
d++;
}
if(d == n) res++;
int l = 0, r = n-1;
while(r < m)
{
l++; r++;
if(m1[s2[l-1]] >= 1 && m1[s2[l-1]] >= m2[s2[l-1]]) d--;
m2[s2[l-1]]--;
m2[s2[r]]++;
if(m1[s2[r]]>=1 && m2[s2[r]] <= m1[s2[r]]) d++;
if(d == n) res++;
}
cout << res;
}
Hãy giúp mọi người biết câu trả lời này thế nào?
Bảng tin