CF144C.Anagram Search
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A string t is called an anagram of the string s, if it is possible to rearrange letters in t so that it is identical to the string s. For example, the string "aab" is an anagram of the string "aba" and the string "aaa" is not.
The string t is called a substring of the string s if it can be read starting from some position in the string s. For example, the string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba".
You are given a string s, consisting of lowercase Latin letters and characters "?". You are also given a string p, consisting of lowercase Latin letters only. Let's assume that a string is good if you can obtain an anagram of the string p from it, replacing the "?" characters by Latin letters. Each "?" can be replaced by exactly one character of the Latin alphabet. For example, if the string p = «aba», then the string "a??" is good, and the string «?bc» is not.
Your task is to find the number of good substrings of the string s (identical substrings must be counted in the answer several times).
字符串 t 被称为字符串 s 的变位词(anagram),当且仅当可以通过重新排列 t 中的字母,使其与字符串 s 完全相同。例如,字符串 "aab" 是 "aba" 的一个变位词,而 "aaa" 则不是。
字符串 t 被称为字符串 s 的子串(substring),当且仅当它可从字符串 s 的某个位置开始连续读出。例如,字符串 "aba" 共有六个子串:"a"、"b"、"a"、"ab"、"ba"、"aba"。
给定一个字符串 s,它由小写拉丁字母和字符 ? 组成;同时还给定一个字符串 p,它仅由小写拉丁字母组成。我们称一个字符串是好的(good),如果可以通过将其中所有 ? 替换为小写拉丁字母(每个 ? 恰好替换为一个拉丁字母),从而得到字符串 p 的一个变位词。例如,若 p=aba,则字符串 "a??" 是好的,而字符串 "?bc" 不是好的。
你的任务是:求出字符串 s 中好的子串的个数(相同的子串若在不同位置出现,需分别计数)。
输入格式
The first line is non-empty string s, consisting of no more than 105 lowercase Latin letters and characters "?". The second line is non-empty string p, consisting of no more than 105 lowercase Latin letters. Please note that the length of the string p can exceed the length of the string s.
第一行是一个非空字符串 s,由不超过 105 个小写拉丁字母和字符 ? 组成。第二行是一个非空字符串 p,由不超过 105 个小写拉丁字母组成。请注意,字符串 p 的长度可能超过字符串 s 的长度。
输出格式
Print the single number representing the number of good substrings of string s.
Two substrings are considered different in their positions of occurrence are different. Thus, if some string occurs several times, then it should be counted the same number of times.
输出一个整数,表示字符串 s 中“好子串”的数量。
若两个子串在原字符串中的出现位置不同,则认为它们是不同的子串。因此,若某个字符串多次出现,则应按其出现次数重复计数。
输入输出样例
输入#1
bb??x??? aab
输出#1
2
输入#2
ab?c acb
输出#2
2
说明/提示
Consider the first sample test. Here the string s has two good substrings: "b??" (after we replace the question marks we get "baa"), "???" (after we replace the question marks we get "baa").
Let's consider the second sample test. Here the string s has two good substrings: "ab?" ("?" can be replaced by "c"), "b?c" ("?" can be replaced by "a").
考虑第一个样例测试。此处字符串 s 有两个“好”子串:“b??”(将问号替换后得到 “baa”)和 “???”(将问号替换后得到 “baa”)。
再考虑第二个样例测试。此处字符串 s 有两个“好”子串:“ab?”(“?” 可替换为 “c”)和 “b?c”(“?” 可替换为 “a”)。
输入解题思路,AI测评打分。不知道怎么写?