Question

In: Computer Science

Using the following text string: axcbramneltodaydy Search for the following pattern: 'today' Specify whether or not...

Using the following text string: axcbramneltodaydy

Search for the following pattern: 'today' Specify whether or not you found the pattern. The minimum requirement is to use the string STL, the brute force method and hard code both the text and the pattern.

For extra credit, you can add any of the following:

1. Do not use the string STL.

2. Allow me to enter both the text string and the pattern, including spaces. You can designate a special end-of-text character for me to include.

3. Use the Boyer-Moore algorithm instead of brute force.

4. Identify the location where the pattern was found within the text.

5. Allow for the possibility that the pattern can appear more than once in the text and identify all of the locations where the pattern was found.

Solutions

Expert Solution

Amongst al the requirements mentioned for extra credits, i am allowing user to enter thetext and pattern manually

Below is the C++ code I hope that i have provided sufficient comments for your better understanding Note that I have done proper indentation but this code is automatically left alligned on this interface

#include <iostream>
#include<string.h>
using namespace std;

int main()
{
//declare 2 strings to take input
string text, pattern;
//Take user input
cout<<"Enter text: ";
getline(cin, text);
cout<<"Enter pattern: ";
getline(cin, pattern);
if(text.find(pattern)!=-1) //pattern is found
cout<<"pattern is found";
else
cout<<"pattern is not found";
return 0;
}


Below is the screenshot of output -

I have tried to explain it in very simple language and I hope that i have answered your question satisfactorily.Leave doubts in comment section if any


Related Solutions

Overview: Pattern-Matching (aka String Search) is the process of algorithmically finding copies of a pattern P...
Overview: Pattern-Matching (aka String Search) is the process of algorithmically finding copies of a pattern P inside a (generally much larger) text T. The goal is to implement and compare classical string-matching algorithms. Input: Your code should work for any text either inputted directly or read in from a file. However, for testing - input file has been provided: The Gettysburg Address (by President Abraham Lincoln, 1863) You should minimally search for these three patterns in each text: FREE, BRAVE,...
Write a C program that can search for a string within a text file, replace it...
Write a C program that can search for a string within a text file, replace it with another string and put results in a new file.
Java String search Design and implement a recursive version of a binary search.  Instead of using a...
Java String search Design and implement a recursive version of a binary search.  Instead of using a loop to repeatedly check for the target value, use calls to a recursive method to check one value at a time.  If the value is not the target, refine the search space and call the method again.  The name to search for is entered by the user, as is the indexes that define the range of viable candidates can be entered by the user (that are...
Write a C++ program using produces Huffman code for a string of text entered by the...
Write a C++ program using produces Huffman code for a string of text entered by the user. Must accept all ASCII characters.
Write a C++ program using produces Huffman code for a string of text entered by the...
Write a C++ program using produces Huffman code for a string of text entered by the user. The string given by the user can be either 1 word or 1000 words. Must accept all ASCII characters. Please do not copy from the internet. This is my 3rd time posting the same question and I have not received a correct answer.
Visual Studio Basic 1: Which string function you will be likely using to search for a...
Visual Studio Basic 1: Which string function you will be likely using to search for a certain pattern in a string? Describe your answer. 2: If you are to find the occurrence of 4-letter string “abcd” regardless of its case combinations, such as “AbCd”, “ABCd” and etc, in a long string, what would you do? Describe your answer.
Prompt the user to enter a string of their choosing. Store the text in a string....
Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: we'll continue our quest in space. there will be more shuttle flights and more shuttle crews and, yes; more volunteers, more civilians, more teachers in space. nothing ends here; our hopes and our journeys continue! You entered: we'll continue our quest in space. there will be more shuttle flights and more shuttle crews and,...
Create a List object that uses the binary search algorithm to search for the string "A"....
Create a List object that uses the binary search algorithm to search for the string "A". Display a message box indicating whether the value was found. Language: C#
Write a version of the binary search algorithm that can be used to search a string...
Write a version of the binary search algorithm that can be used to search a string vector object. Also, write a program to test your algorithm. (Use the selection sort algorithm you developed in Programming Exercise 12 to sort the vector.) Your program should prompt the user to input a series of strings, ending the input stream with zzz. The program should then prompt the user to search for a specific string in the list. If the string is found...
Create this C++ program using classes 1. Create a file text file with a string on...
Create this C++ program using classes 1. Create a file text file with a string on it 2. Check the frecuency of every letter, number and symbol (including caps) 3. Use heapsort to sort the frecuencys found 4. Use huffman code on the letters, symbols or numbers that have frecuencys I created the file, and the frecuency part but i'm having trouble with the huffman and heapsort implementation.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT