void FindPattern(string inputstring)
{
int length = inputstring.length()
int currentEnd = 1; //end position of the first substring to be searched
int currentBeg = 0; //begining position of the first substring
int Result = 0;
char* Pattern= null;
while( currentEnd length-3) // we look for a pattern only until the 3rd
last char
{
Pattern = inputstring.substr(currentBeg,CurrentEnd);
// Search for the pattern within the input string from Next charecter of
CurrentEnd.
Result = inputstring.find(Pattern, CurrentEnd+1) ;
// If Pattern Not found , Increase CurrentBeg by 1 char and start search
for next pair of chars
if( Result = -1 )
{
CurrentBeg++;
CurrentEnd = CurrentBeg + 1;
Continue;
}
// If Pattern is Found . Print it! and Increase the Current End by 1 so
that now you search for a bigger pattern starting with same //first
charecter.
Printf(%s\n,Pattern.c_str());
CurrentEnd++;
}
}
On Wed, Feb 3, 2010 at 1:30 AM, ankit mahendru ankit.mahend...@gmail.comwrote:
Rephrasing the question again :
Q. Find all the patterns which are present in the character array given. A
pattern is a sub-array containing 2 or more chars and is having a frequency
of more than one.
Example:
i/p: aabcdadabc
o/p: ab, abc, bc, da
basically what we have to search is those sub-string(s) of length 2 or more
which repeats itself(not necessarily twice, but 'n' number of times). In the
above example 'ab' has been highlighted with red in order to make it
clear.
Another example:
i/p : fghjerhjfgjefgh
o/p: fg, je , hj, fgh
I hope its clear now.
Thanks
Ankit Mahendru
On Tue, Feb 2, 2010 at 8:31 PM, vivek bijlwan viv...@gmail.com wrote:
explain the question a little further please
On Tue, Feb 2, 2010 at 11:03 AM, Algoose Chase harishp...@gmail.comwrote:
Hope you meant a pattern is sub-array containing 2 or more UNIQUE chars.
hope based on dfn, abcd is also a pattern in the input you have given.
On Tue, Feb 2, 2010 at 1:11 AM, ankit mahendru
ankit.mahend...@gmail.com wrote:
Q. Find all the patterns once which are present in the character array
given. A pattern is a sub-array containing 2 or more chars.
Example:
i/p: aabcdadabc
o/p: ab, abc, bc, da
--
You received this message because you are subscribed to the Google
Groups Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
.
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
.
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
.
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
.
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.