Documente Academic
Documente Profesional
Documente Cultură
(https://www.codechef.com/certification/data-structures-and-algorithms/about?
Home (/) » Compete (/contests/) » April Challenge 2019 Division 2 (/APRIL19B?order=desc&sortBy=successful_submissions) » Friend or Girlfriend
utm_source=website&utm_medium=adstrip&utm_campaign=mar31adstrip)
Tweet
Like Share 18 people like this. Be the first of your friends.
(https://twitter.com/share)
All submissions for this problem are available.### Read problem statements in All Submissions (/APRIL19B/status/STRCH)
Hindi (http://www.codechef.com/download/translated/APRIL19/hindi/STRCH.pdf),
Bengali
Successful Submissions
(http://www.codechef.com/download/translated/APRIL19/bengali/STRCH.pdf),
Mandarin Chinese
(http://www.codechef.com/download/translated/APRIL19/mandarin/STRCH.pdf),
Russian
(http://www.codechef.com/download/translated/APRIL19/russian/STRCH.pdf), and
Vietnamese
(http://www.codechef.com/download/translated/APRIL19/vietnamese/STRCH.pdf)
as well.
Shlok and Sachin are good friends. Shlok wanted to test Sachin, so he wrote down
a string S with length N and one character X . He wants Sachin to find the
number of different substrings of S which contain the character X at least once.
Sachin is busy with his girlfriend, so he needs you to find the answer.
Input
The first line of the input contains a single integer T denoting the number of
test cases. The description of T test cases follows.
The first line of each test case contains a single integer N .
The second line contains a string S with length N , followed by a space and a
character X .
Output
For each test case, print a single line containing one integer — the number of
substrings of S that contain X .
Constraints
1 ≤ T ≤ 1, 000
6
1 ≤ N ≤ 10
Subtasks
We use cookies to improve your experience and for analytical purposes. Read our Privacy Policy (/privacy-policy) and Terms (/terms) to know more. You consent to our cookies if
Subtask #1 (30 points): the sum of N over all test cases does not exceed 103 Okay
you continue to use our website.
https://www.codechef.com/APRIL19B/problems/STRCH 1/3
Subtask #2 (70 points): original constraints
25/04/2019 Friend or Girlfriend | CodeChef
Example Input
2
3
abb b
6
abcabc c
Example Output
5
15
Explanation
Example case 1: The string "abb" has six substrings: "a", "b", "b", "ab", "bb",
"abb". The substrings that contain 'b' are "b", "b", "ab", "bb", "abb".
Languages: C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS
gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, 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, kotlin, PERL6,
TEXT, SCM chicken, PYP3, CLOJ, R, COB, FS
Comments
© 2009 Directi Group (http://directi.com). All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs (http://www.sphere-research.com)
In order to report copyright violations of any kind, send in an email to copyright@codechef.com (mailto:copyright@codechef.com)
(http://directi.com)
Initiatives
We use cookies to improve your experience and for analytical purposes. Read our Privacy Policy (/privacy-policy) and Terms (/terms) to know more. You consent to our cookies if
Okay
you continue to use our website.
https://www.codechef.com/APRIL19B/problems/STRCH 3/3