Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <unordered_map>
- using namespace std;
- int main() {
- string a, b;
- cin >> a >> b;
- unordered_map<char, int> alf_a;
- for (auto el: a) {
- ++alf_a[el];
- }
- int cur_diff = alf_a.size();
- unordered_map<char, int> cur_alf;
- int ans = 0;
- for (int i = 0; i < a.size(); ++i) {
- ++cur_alf[b[i]];
- if (cur_alf[b[i]] == alf_a[b[i]]) {
- --cur_diff;
- } else if (cur_alf[b[i]] - 1 == alf_a[b[i]]) {
- ++cur_diff;
- }
- if (cur_diff == 0) ++ans;
- }
- for (int i = 0; i + a.size() < b.size(); ++i) {
- --cur_alf[b[i]];
- if (cur_alf[b[i]] == alf_a[b[i]]) {
- --cur_diff;
- } else if (cur_alf[b[i]] + 1 == alf_a[b[i]]) {
- ++cur_diff;
- }
- ++cur_alf[b[i + a.size()]];
- if (cur_alf[b[i + a.size()]] == alf_a[b[i + a.size()]]) {
- --cur_diff;
- } else if (cur_alf[b[i + a.size()]] - 1 == alf_a[b[i + a.size()]]) {
- ++cur_diff;
- }
- if (cur_diff == 0) ++ans;
- }
- cout << ans;
- }
- //abbac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement