![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Jan 2006
Location: Texas
Posts: 36
Rep Power: 0
![]() |
Finding Patterns
Ok... please don't flame me for asking this again, but i didnt ask it properly last time and i did not word it correctly...
Is there any way in C++ to go through 2 strings of characters, for example 141337545434544543 and 325452134544534513375, and find similar patterns (look at the bold)... take all those similar patterns, and display them on a seperate page??? These patterns must be ATLEAST 5 characters each. It does not matter where they are in the strings... just as long as those patterns are the same. [EXAMPLE] (Pg 1) Pattern 1: 141337545434544543 Pattern 2: 325452134544534513375 (Pg 2) Following occurs in both patterns: 13375 45445 [/EXAMPLE] Please, if you can, explain me a code that i can use to do this. THANK YOU IN ADVANCE! |
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4
![]() |
If the strings are short, you can try to brute force it like:
1) break the first string in n(n is the pattern length) char long strings. eg: if string==123456789, n==5 you break the string in 5 string viz.12345, 23456,34567,45678,56789 2) break the second string similarly. 3) now you have two lists containing patterns. you can compare each to each other and find the matches. This is a very inefficient algorithm. But it is the first thing that came to my mind.
__________________
PFO - My daily dose of technology. |
|
|
|
|
|
#3 | |
|
Programmer
Join Date: Jan 2006
Location: Texas
Posts: 36
Rep Power: 0
![]() |
Quote:
only thing is my string is 10kb in notepad... kinda long... hopefully it will still work... Thanks |
|
|
|
|
|
|
#4 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
At least five is not the same thing as exactly five. You need to start with the first character of the first string, use a 5-character needle, and search every position in the second string, then change needle size and do it all again. There are matching algorithms that can shorten this process below the number of comparisons required for the raw brute force approach, but I don't happen to have a link handly. Google would probably work.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#5 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 852
Rep Power: 4
![]() |
I think you mean change need location, rather than size.
Once you have found a 5 character match, it is pretty easy to then check how big the actual match is, as you now the location of the start of both matching patterns. |
|
|
|
|
|
#6 |
|
Programmer
Join Date: Jan 2006
Location: Texas
Posts: 36
Rep Power: 0
![]() |
Google isnt being nice to me, sorry...
exactly 5 will work, i can just give the user an option and make many pages, replacing the 5 with anything... thanks for your suggestion... but can someome give me some code? im a very big newbie in C++. thank you. |
|
|
|
|
|
#7 | |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Quote:
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
|
#8 |
|
Professional Programmer
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4
![]() |
Learn C++. Take your time. Research the problem in more detail. Write some code then come back if you have any problems. This is the expected approach if you want others to help you.
__________________
PFO - My daily dose of technology. |
|
|
|
|
|
#9 |
|
Programmer
Join Date: Jan 2006
Location: Texas
Posts: 36
Rep Power: 0
![]() |
sorry but i have to turn this on the due date... saturday morning! so i dont have time to extensively learn c++. i wll after this project.... i just want a feel for it now.
thanks |
|
|
|
|
|
#10 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Forgive me, but it seems unlikely in the extreme that you were assigned this in the last day or two, and it's due Saturday, unless you've had much more preparation than you've taken advantage of.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|