This problem was raised in comp.lang.perl. misc, and the poster was
concerned, among other things, by the speed of execution.
Since C is faster than perl, I wonder how a C coder would solve it?
Given a *very* long string, A, and a shorter string, B, extract all
substrings of A that differ from B in at most N positions.
For example:
N = 2
A = 'abcdefaacdefxb cxfaaabcdefaaaa cdxf'
B = 'abcdef'
the substrings are 'abcdef' at offsets 0 & 19, 'aacdef' at offset 6, and
'aacdxf' at offset 27. 2 2828
"Pilcrow" <Pi******@gmail .comwrote in message
news:9p******** *************** *********@4ax.c om...
This problem was raised in comp.lang.perl. misc, and the poster was
concerned, among other things, by the speed of execution.
Since C is faster than perl, I wonder how a C coder would solve it?
Given a *very* long string, A, and a shorter string, B, extract all
substrings of A that differ from B in at most N positions.
For example:
N = 2
A = 'abcdefaacdefxb cxfaaabcdefaaaa cdxf'
B = 'abcdef'
the substrings are 'abcdef' at offsets 0 & 19, 'aacdef' at offset 6, and
'aacdxf' at offset 27.
Here's how /I/ did, as an occasional C coder; this assumes substrings can
overlap:
#include <stdio.h>
#include <string.h>
int main(void) {
char *a="abcdefaacde fxbcxfaaabcdefa aaacdxf";
char *b="abcdef";
int n=2;
int blen;
int i,j,k,c;
blen=strlen(b);
k=strlen(a)-blen+1;
for (i=0; i<k; ++i) {
/* Compare substring a[i]..a[i+blen-1] with b*/
c=0;
for (j=0; j<blen; ++j)
if (a[i+j]!=b[j]){
++c;
if (c>n) break;
}
if (c<=n) {
printf("Offset: %d Substring: ",i);
for (j=0; j<blen; ++j) printf("%c",a[i+j]);
puts("");
}
}
}
--
Bartc
Pilcrow wrote:
This problem was raised in comp.lang.perl. misc, and the poster was
concerned, among other things, by the speed of execution.
Since C is faster than perl,
What a nonsensical assertion!
[...] I wonder how a C coder would solve it?
Given a *very* long string, A, and a shorter string, B, extract all
substrings of A that differ from B in at most N positions.
For example:
N = 2
A = 'abcdefaacdefxb cxfaaabcdefaaaa cdxf'
B = 'abcdef'
the substrings are 'abcdef' at offsets 0 & 19, 'aacdef' at offset 6, and
'aacdxf' at offset 27.
I don't see anything C-specific about the question.
A few ideas come to mind, but they'd be better suited to
a general programming or algorithms group than to this one.
--
Eric Sosman es*****@ieee-dot-org.invalid This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: spam |
last post by:
Is there a well-known algorithm for replacing many substrings in a
string? For example, I'd like to take the string "abc def ghi jkl mno
pqr" and replace, say, every instance of "abc", "ghi", and "mno" with
another value.
Of course the brute-force approach is straight forward. Just iterate
over the full string N times (once for "abc", "ghi", and "mno"), find
all instances, and replace them using the normal std::string member...
|
by: Evaluating Fuzzy SW |
last post by:
Hi All
We are using soundex (and later tried Nysiis) for fuzzy name search
software. But we faced a lot of problems the search accuracy was not very
good also we saw a lot of misses of relevant names.
There are many problems other than precision and accuracy, with soundex and
NYSIIS.
|
by: Will McGugan |
last post by:
Hi,
Is there a simple way of replacing a large number of substrings in a
string? I was hoping that str.replace could take a dictionary and use it
to replace the occurrences of the keys with the dict values, but that
doesnt seem to be the case.
To clarify, something along these lines..
>>> dict_replace( "a b c", dict(a="x", b="y") )
|
by: War Eagle |
last post by:
I've been looking at .substring and .trim methods and I still have a question about extracting substrings from a textbox. Basically the textbox contains the full path to a file ... for example C:\testfile.txt or ... C:\download\temp\dlls\testfile.dll
I want to be able to extract the file name from this textbox (and put it in a string) when I click a button. Can someone illustrate how to write this line of code?
|
by: michael.f.morrison |
last post by:
Hi all,
Does anyone now if there is a way to do a fuzzy string compare in c#?
For example, comparing 'cat' to 'cats' would return something like a
90% match ratio. I was told that this type of fuctionality exists in
Perl but I can't find anything about it in c#.
Thanks
Mike
| |
by: Randy |
last post by:
Is there any way to do this? I've tried tellg() followed by seekg(),
inserting the stream buffer to an ostringstream (ala os << is.rdbuf()),
read(), and having no luck.
The problem is, all of these methods EXTRACT the data at one
point or another. The other problem is there appears to be NO
WAY to get at the actual buffer pointer (char*) of the characters
in the stream. There is a way to get the streambuf object
associated with the...
|
by: BBands |
last post by:
I have some CDs and have been archiving them on a PC. I wrote a Python
script that spans the archive and returns a list of its contents:
...]. I wanted to add a search function to
locate all the versions of a particular song. This is harder than you
might think. For example the Cajun "national anthem" is Jolie Blond,
but it can be spelled several different ways jolie, joli, blon, blond,
etc... In addition the various online services that...
|
by: ashilyas |
last post by:
Hi all,
I am new to this forum as well as Visual Basic. I haven't been able to find a resource that tells me what functions are available in Visual Basic like you can find the listing in C++ and java. If someone can tell me how to get that it would be great.
My question though is, I have a string variable in my VB code that has a long string (a combination of smaller strings seperated by ";") I need to extract all theses...
|
by: Jason S |
last post by:
Is there a way to get the position of multiple substrings that match a
regexp without using closures? match() returns the substrings
themselves, not the positions, and search() seems to only return the
first position. Here's what seems to work (under Shanti Rao's jsdb.exe
shell) but I get a bit nervous about using closures...
function bind_cache(x) { return function (subs,ofs)
{ x.push(); return ""; }}
x=;
f=bind_cache(x);
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |