Hansels Ordeal I
All submissions for this problem are available.
Gretel has been kidnapped by the evil witch and it is up to Hansel to save her. Hansel comes across a piece of parchment containing the witch's plans which he must use to decipher the only clue left by Gretel.
You are provided with the plans in the form of a string A and a string B containing Gretel's last words. You must help Hansel out by determining the number of occurrences of substrings in source string A whose characters when rearranged produce string B.
The first line of input contains a single integer T giving the number of test cases. The following 2×T lines define the T test cases. Every test case consists of 2 lines. The first line of contains string A. The second contains string B.
Note: All characters in the strings are between uppercase 'A' and 'Z'.
The output contains T lines, each a single integer - the number of occurrences for its corresponding test case.
1 ≤ T ≤ 10
1 ≤ |A| ≤ 105
1 ≤ |B| ≤ 104
1 BAADEABAABA ABA
The substrings are BAA, ABA, BAA, AAB, ABA.
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, PYP3, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.