Can anyone suggest an algorithm or function to generate combinations/
permutations of a group of substrings stored in a vector. The
substrings consists of 3 letters and the resulting string combinations
should be of a size that is a multiple of 3. 2 2274
On 24 Sep, 06:53, zgfar...@gmail. com wrote:
Can anyone suggest an algorithm or function to generate combinations/
permutations of a group of substrings stored in a vector. The
substrings consists of 3 letters and the resulting string combinations
should be of a size that is a multiple of 3.
check next_permutatio n() in STL. zg******@gmail. com wrote:
Can anyone suggest an algorithm or function to generate combinations/
permutations of a group of substrings stored in a vector. The
substrings consists of 3 letters and the resulting string combinations
should be of a size that is a multiple of 3.
First, the problem is obfuscated (I suspect, it is homework): the groups of
3 letters just hide the abstract problem of generating permutations and
combinations. So, first take the input data apart and create a
std::vector< std::string >
that stores those groups of three letters.
Now, for permutations, life is easy because STL has next_permutatio n built
in.
For combinations, note that the problem of enumerating all combinations of
length n from a set of k items is equivalent to listing all n-digit
counting numbers in base k (because if you have such a number, each digits
represents one of k items and you have made exactly n such choices). Thus,
you could use a
std::vector< unsigned int >
and implement "add 1" in base k.
Best
Kai-Uwe Bux This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Leandro Pardini |
last post by:
Hello there,
I'm trying to process a binary file and I really don't know how. The
story: gPhoto2 downloads the images from my camera just fine, but
small areas of 10x3 pixels are screwed up. I found exactly where the
problem happens and wrote a simple interpolation filter that works
like a charm... under DOS, using the old QuickBasic. I've used Perl
for a while, but never to handle binary data, so I'm at a loss; and I
really want to get...
|
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: 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: C3 |
last post by:
I have to process some data in C that is given to me as a char * array. I
have a fairly large number of substrings (well, they're not actually
printable, but let's treat them as strings) that I have to search for in the
data.
I need to keep a count of how often each of these substrings occurs in my
original data and then print it out at the end.
This is a fairly mundane task, but since I have so many substrings, it's a
pain having to...
|
by: Robert Dodier |
last post by:
Hello all,
I'm trying to find substrings that look like 'FOO blah blah blah'
in a string. For example give 'blah FOO blah1a blah1b FOO blah2
FOO blah3a blah3b blah3b' I want to get three substrings,
'FOO blah1a blah1b', 'FOO blah2', and 'FOO blah3a blah3b blah3b'.
I've tried numerous variations on '.*(FOO((?!FOO).)*)+.*'
and everything I've tried either matches too much or too little.
| |
by: Girish Sahani |
last post by:
Given a length k string,i want to search for 2 substrings (overlap
possible) in a list consisting of length k-1 strings. These 2 substrings
when 'united' give the original string.
e.g given 'abc' i want to search in the list of 2-length strings
to extract either
1) 'ab and 'ac' OR ('a' common)
2) 'ab' and 'bc' OR ('b' common)
3) 'ac' and 'bc' ('c' common)
In all these cases, one of the letter is common in the 2 strings.
|
by: girish |
last post by:
Hi,
I want to generate all non-empty substrings of a string of length >=2.
Also,
each substring is to be paired with 'string - substring' part and vice
versa.
Thus, gives me , , , , , ] etc.
Similarly, 'abcd' should give me , , , , , ,, ,
, , , , ,]
I've tried the following but i cant prevent duplicates and i'm missing
|
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: Pilcrow |
last post by:
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 = 'abcdefaacdefxbcxfaaabcdefaaaacdxf'
|
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: 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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |