[Solved] C Programming Question Don T Know Write Code Q37260094
C programming question…



![Main Idea: Find the amount of substring@[I,r] Substring: In string Abababababaab, a substring could be a, b, ab, aba,](https://media.cheggcdn.com/media%2F234%2F234013b3-ab7b-42c3-90ad-4dfc6427843c%2Fphpn05UJe.png)
![Aggregate: (store answers in head array) for (int í = 0; î < slen- (plen - 1); i++) head[i+1]-check(i) +head[i] We consider](https://media.cheggcdn.com/media%2Ff5e%2Ff5e39fa1-9c31-4486-866a-b68e7b7827d2%2FphpPvYEgx.png)
I don’t know how to write this code.
Description “Death is like the wind, always by my side.”, said by a famous streamer, Mr. Yasuoo Mr. Yasuoo is known for his skill “Slides up”. When Mr. Yasuoo slides across a string S, he will be asked t questions. in each question, he should respond the number of occurrences of substring s, given a interval Of [ , r Specifically, if the string S is “hasahasasaki” and the substring s is “sa”, Mr. Yasuoo should answer 2 given the interval of [3, 9 Since the interval [3-9] indicates “sahasas”, the number of occurrences of substring “sa” is then 2. Note that the index of string starts from 1 and contains only ‘a-‘z’ Help Mr. Yasuoo to answer these questions before he starts feeding, ASAP! (the photo of the famous streamer) Input Input should contain multiple lines First line indicates the string S (1 length of S103) Second line gives the substring s ( 1c length of s 10% ) the string contains only lower case a-z. Third line contains one integer t (1-t< 2*10°) each of the following t lines gives two integer [l , r], where ( 1 r仁length of S) Output For each question, you are asked to print the the number of occurrences of substringS Your program should present a single “In’ at the end of output Sample Input Download hasahasasaki sa 3 3 9 14 23 Sample Output 0 Main Idea: Find the amount of substring@[I,r] Substring: In string “Abababababaab”, a substring could be ‘a, ‘b, ‘ab’, ‘aba, Common Error: Brute force, attempt to iterate all possibilities ->TLE ! RECALL Aggregate answers in an array (appeared in our labs before) For example, counting, 1 2 233 3 3 3 3 4, indicates 0 (Not increasing) Specifically, ans[i+1sthi]ansi (sth: some useful functions or efficient transformation) sth: something useful -> “check” function We check if substring p exists in string S A check is valid (return 1) when every ‘char’ in p are equal to those of S The amount of ‘char’ depends on substring p, which is ‘plen’, a length of p In others words, if any ‘char’ mismatches, the check fails int check(int idex) ( for (int j-0; j < plen ; j++) return 0 return 1; (S: input string; p: an objective substring) Aggregate: (store answers in ‘head’ array) for (int í = 0; î < slen- (plen – 1); i++) head[i+1]-check(i) +head[i] We consider all of the possible position that a substring p may exist It starts from the beggining of S, ends in ‘slen’ – ‘plen’1 For example, aaabb. Checking substring bbb @ bb is trivial, since the length of bbb is > len(bb) In interval [I, r, we have scanf ( “%d”, while (g– &q ) ; int 1, ri scanf ( “%ded”, &1, &r); int h -r – plen+1, b -1-1 int ans-h<b20head h printf dIn”, ans) -head bi We calculate the answer through our ‘head’. Since we’ve already stored the answers before, it’s easy to get the correct answer by simply subtraction. Note that, if the length of p is>the given interval [I, r], Mr. Yasuoo will gg. (The answer should be 0, meaningless) Show transcribed image text Description “Death is like the wind, always by my side.”, said by a famous streamer, Mr. Yasuoo Mr. Yasuoo is known for his skill “Slides up”. When Mr. Yasuoo slides across a string S, he will be asked t questions. in each question, he should respond the number of occurrences of substring s, given a interval Of [ , r Specifically, if the string S is “hasahasasaki” and the substring s is “sa”, Mr. Yasuoo should answer 2 given the interval of [3, 9 Since the interval [3-9] indicates “sahasas”, the number of occurrences of substring “sa” is then 2. Note that the index of string starts from 1 and contains only ‘a-‘z’ Help Mr. Yasuoo to answer these questions before he starts feeding, ASAP!
(the photo of the famous streamer) Input Input should contain multiple lines First line indicates the string S (1 length of S103) Second line gives the substring s ( 1c length of s 10% ) the string contains only lower case a-z. Third line contains one integer t (1-tTLE ! RECALL Aggregate answers in an array (appeared in our labs before) For example, counting, 1 2 233 3 3 3 3 4, indicates 0 (Not increasing) Specifically, ans[i+1sthi]ansi (sth: some useful functions or efficient transformation) sth: something useful -> “check” function We check if substring p exists in string S A check is valid (return 1) when every ‘char’ in p are equal to those of S The amount of ‘char’ depends on substring p, which is ‘plen’, a length of p In others words, if any ‘char’ mismatches, the check fails int check(int idex) ( for (int j-0; j
Expert Answer
Answer to C programming question… I don’t know how to write this code…. . . .
OR

