Search
 
SCRIPT & CODE EXAMPLE
 

CPP

determining a string is subsequence of another

// Iterative C++ program to check
// if a string is subsequence
// of another string
#include <cstring>
#include <iostream>
using namespace std;

// Returns true if str1[] is a
// subsequence of str2[]. m is
// length of str1 and n is length of str2
bool isSubSequence(char str1[], char str2[], int m, int n)
{
	int j = 0; // For index of str1 (or subsequence

	// Traverse str2 and str1, and
	// compare current character
	// of str2 with first unmatched char
	// of str1, if matched
	// then move ahead in str1
	for (int i = 0; i < n && j < m; i++)
		if (str1[j] == str2[i])
			j++;

	// If all characters of str1 were found in str2
	return (j == m);
}

// Driver program to test methods of graph class
int main()
{
	char str1[] = "gksrek";
	char str2[] = "geeksforgeeks";
	int m = strlen(str1);
	int n = strlen(str2);
	isSubSequence(str1, str2, m, n) ? cout << "Yes "
									: cout << "No";
	return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ comments 
Cpp :: C++ Rectangular Form 
Cpp :: crtdbg c++ 
Cpp :: ue4 set size of widget c++ 
Cpp :: fast scan in c++ 
Cpp :: quiz arrary and pointers in c++ 
Cpp :: c ++ loop 
Cpp :: vector stop at newline 
Cpp :: c++ start thread later 
Cpp :: how to insert variable into string c++ 
Cpp :: Reading package lists... Done Building dependency tree Reading state information... Done mysql-server is already the newest version (5.7.36-0ubuntu0.18.04.1). 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. 
Cpp :: sro in c++ 
Cpp :: C++ Display Numbers from 1 to 5 
Cpp :: Patrick and Shopping codeforces in c++ 
Cpp :: c pointer syntax 
Cpp :: pycuda install failed microsoft c++ 
Cpp :: c++ fps sleep while loop 
Cpp :: syntax of member function in c++ 
Cpp :: ue4 log 
Cpp :: string class cpp 
Cpp :: lambda - print-out array and add comment 
Cpp :: icon on win32 button 
Cpp :: C++ initializing a thread with a class/object with parameters 
Cpp :: http://dcnet.ddns.ma/Connecter_Tuteur 
Cpp :: scope resolution operator in c++ 
Cpp :: middle node of linked list 
Cpp :: vector to char array c++ 
Cpp :: open a url with dev c 
Cpp :: do while loop c++ 
C :: how to store a user input with spaces in c 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =