Question

C programming question...Description Death is like the wind, always by my side.,said by a famous streamer, Mr. Yasuoo. Mr. Yasuoo is known for his sk(the photo of the famous streamer) Input Input should contain multiple lines First line indicates the string S ( 1<= length oOutput For each question, you are asked to print the the number of occurrences of substring s. Your program should present a

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 ofL 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 then2 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
0 0
Add a comment Improve this question Transcribed image text
Answer #1

// C program to determine the number of occurrences of substring in a string in a given interval

#include <stdio.h>

#include <stdlib.h>

int main(void) {

               // declare variables

               char S[1000], s[1000];

               int t, l,r;

               fflush(stdout);

               // read the string, substring and number of test cases

               scanf("%s %s %d",S,s,&t);

               int count;

               int i,j,k;

               // loop to read each test case and determine the result

               for(i=0;i<t;i++)

               {

                              fflush(stdout);

                              // read the integers l and r

                              scanf("%d %d",&l,&r);

                              count = 0;

                              // loop to count the number of occurrence of s in S in the given interval [l,r]

                              // since index of array starts from 0, so start from l-1

                              for(j=l-1;j<r-1;)

                              {

                                             if(S[j] == s[0]) // if the first letter matches

                                             {

                                                            j++;

                                                            // loop through the remaining the string and check

                                                            for(k=1;s[k]!='\0';k++)

                                                            {

                                                                           if(S[j] != s[k]) // if character do not match

                                                                           {

                                                                                          count--; // decrement the count

                                                                                          j--; // decrement t j

                                                                                          break; // break from the loop

                                                                           }

                                                                                          j++; // increment j

                                                            }

                                                                           count++; //increment count

                                             }else

                                                            j++;

                              }

                              // print the count of occurrence

                              printf("%d\n",count);

               }

               return EXIT_SUCCESS;

}

//end of program

Output:

Input:

hasahasasaki sa 3 9 1 4

Output:

210

Add a comment
Know the answer?
Add Answer to:
Description Death is like the wind, always by my side.",said by a famous streamer, Mr. Yasuoo. Mr...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Detecting Substrings (C++ Version) Introduction A very common task that is often performed by programs that...

    Detecting Substrings (C++ Version) Introduction A very common task that is often performed by programs that work with text files is the problem of locating a specific substring within the file. I am sure we’ve all done this many times when working with Word, Notepad, or other editors. Since we don’t have a GUI or other means of displaying the contents of a file all at once, let’s modify the problem slightly. Rather than locating a specific substring within a...

  • You are given a set of ABC cubes for kids (like the one shown below) and a word. On each side of ...

    You are given a set of ABC cubes for kids (like the one shown below) and a word. On each side of each cube a letter is written 7 FI 0 You need to find out, whether it it possible to form a given word by the cubes For example, suppose that you have 5 cubes: B1: MXTUAS B2:OQATGE ВЗ: REwMNA B4: MBDFAC В5: IJKGDE (here for each cube the list of letters written on its sides is given) You...

  • Python Problem, just need some guidance with the description, pseudocode and run time. I believe this...

    Python Problem, just need some guidance with the description, pseudocode and run time. I believe this is an 0-1 knapsack problem? Shopping Spree: (20 points) Acme Super Store is having a contest to give away shopping sprees to lucky families. If a family wins a shopping spree each person in the family can take any items in the store that he or she can carry out, however each person can only take one of each type of item. For example,...

  • PA #1: Word Counter Tabulating basic document statistics is an interesting exercise that leverages your knowledge...

    PA #1: Word Counter Tabulating basic document statistics is an interesting exercise that leverages your knowledge of strings, files, loops, and arrays. In this homework, you must write a C++ program that asks the user for an input and output file. For each line in the input file, write a modified line containing a line number to the output file. Additionally, calculate the number of paragraphs, lines, words, and characters. Write the summary information to the bottom of the output...

  • C language huffman This exercise will familiarize you with linked lists, which you will need for...

    C language huffman This exercise will familiarize you with linked lists, which you will need for a subsequent programming Getting Started assignment Overview Requirements Getting Started Submit Start by getting the files. Type 264get hw13 and then cd hw13 from bash. Pre-tester You will get the following files: Q&A Updates 1. huffman.h: An empty header file, you have to define your own functions in this homework. 2. huffman.c: An empty c file, you have to define your own functions in...

  • Banks issue credit cards with 16 digit numbers. If you've never thought about it before you...

    Banks issue credit cards with 16 digit numbers. If you've never thought about it before you may not realize it, but there are specific rules for what those numbers can be. For example, the first few digits of the number tell you what kind of card it is - all Visa cards start with 4, MasterCard numbers start with 51 through 55, American Express starts with 34 or 37, etc. Automated systems can use this number to tell which company...

  • hey please answer in python 3 This is the test for these questions. it has to...

    hey please answer in python 3 This is the test for these questions. it has to be exactly the same as the Expected output. notice my code is very close to getting it but im always off by 0.01 or 0.02. Thank you for the help! In this exercise, you will build a program to process files containing paragraphs. The aim of the program is to simply count the number of words and compute their length. The file, however, may...

  • Please help me ONLY for the second method : public static int[] runningGroups(String[] inputFileNames) throws IOException....

    Please help me ONLY for the second method : public static int[] runningGroups(String[] inputFileNames) throws IOException. The second method has an "array of files as a parameter". and return int [ ]. Each element of the return array is the number of group that can get from the first method.    I got an error Exception in thread "main" java.lang.NullPointerException Here my code: import java.io.*; import java.util.ArrayList; import java.util.Scanner; public class RunningGroups { public static void main(String[] args) throws IOException...

  • Code to be written in C++: Initially, you will be given symbols printed in a preorder...

    Code to be written in C++: Initially, you will be given symbols printed in a preorder traversal of a boolean expression tree. The internal nodes of the tree will contain one of the following operators: & (and), | (or), ^ (exclusive-or), or ! (not). The nodes containing the first three operators will have two children, while the nodes containing the ! operator will contain only a left child. The leaves of the tree will contain an operand - either f...

  • Write a c++ program in that file to perform a “Search and Replace All” operation. This...

    Write a c++ program in that file to perform a “Search and Replace All” operation. This operation consists of performing a case-sensitive search for all occurrences of an arbitrary sequence of characters within a file and substituting another arbitrary sequence in place of them. Please note: One of the biggest problems some students have with this exercise occurs simply because they don’t read the command line information in the course document titled “Using the Compiler’s IDE”. Your program: 1. must...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT