Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Thi function takes in a list of characters or text and a body of characters (bot

ID: 3838827 • Letter: T

Question

Thi function takes in a list of characters or text and a body of characters (both in the range of a-z, lowercase only) and return a list giving the occurrence count for each string given. The counts returned should correspond to the indices they appear in the input seqs vector. For example:

seqs: [a, aa, ab, aab]

text: aaaabab

Then you have: Occurrences of a: aaaabab, aaaabab, aaaabab, aaaabab, aaaabab (5 in total)

Occurrences of aa: aaaabab, aaaabab, aaaabab (3 in total)

Occurrences of ab: aaaabab, aaaabab (2 in total)

Occurrences of aab: aaaabab (1 in total) return: [5,3,2,1]

I know a solution to this using #include but im trying to figure out another solution using other data structures thanks.. c++ only

Explanation / Answer

Use the following code to develop the required program(need modification)

#include<bits/stdc++.h>
using namespace std;

int main()
{
   char seqs[100][100];
   char text[100];

   int n;

   cout<<"Enter the number of seqs: ";
   cin>>n;
  
   for(int i=0 ; i<n ; i++)
   {
       cin>>seqs[i];
   }

   cout<<"Enter the text: ";
   cin>>text;

   int len=strlen(text);
   int count=0;
   vector<int> v;

   for(int i=0 ; i<n;i++)
   {
       count=0;
       for(int j=0; j<len ; j++ )
       {
           char *ptr=strstr(text+j,seqs[i]);
           if(ptr!=NULL)  
           {   count++;
               //cout<<*ptr;
           }
       }
       v.push_back(count);
   }

   for(int i=0;i<v.size();i++)
       cout<<"Occurrences of"<<seqs[i]<<":"<<v[i]<<" "<<endl;
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote