Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _USE_MATH_DEFINES
- #include<stdio.h>
- #include<iostream>
- #include<vector>
- #include<cmath>
- #include<algorithm>
- #include<memory.h>
- #include<map>
- #include<set>
- #include<queue>
- #include<list>
- #include<sstream>
- #include<cstring>
- #include<numeric>
- #include<limits.h>
- using namespace std;
- const int Pc = 1e5;
- const int Nc = 1e8;
- const int P = 8e4;
- const int N = 5e5;
- char word[Pc];
- char t[Nc];
- int w[P];
- int txt[N];
- int p[3]{
- 1, 31, 961
- };
- int gethash(char a, char b, char c) {
- return a + b * p[1] + c * p[2];
- }
- map<int, int> cnt;
- map<int, int> cur;
- bool check() {
- for (auto c : cur) {
- if (cnt.count(c.first) == 0 || cnt[c.first] != c.second) {
- return false;
- }
- }
- return true;
- }
- int main() {
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- #endif
- gets_s(word);
- gets_s(t);
- int lenw = strlen(word);
- int id = 0;
- for (int i = 0; i < lenw; i+=4) {
- w[id++] = gethash(word[i], word[i + 1], word[i + 2]);
- }
- for (int i = 0; i < id; i++) {
- cnt[w[i]]++;
- }
- int lent = strlen(t);
- int idx = 0;
- for (int i = 0; i < lent; i += 4) {
- txt[idx++] = gethash(t[i], t[i + 1], t[i + 2]);
- }
- if (lenw > lent) {
- printf("0");
- return 0;
- }
- for (int i = 0; i < id; i++) {
- cur[txt[i]]++;
- }
- int res = 0;
- if (check())
- res++;
- for (int i = id; i < idx; i++) {
- cur[txt[i - id]]--;
- if (cur[txt[i - id]] == 0) {
- cur.erase(txt[i - id]);
- }
- cur[txt[i]]++;
- if (check())
- res++;
- }
- printf("%d", res);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement