|
You've not supplied near enough information to form a useful pattern. Based on the one example of "a b" producing "a b c d e", most anything is possible such as "s t" producing "s t u v w". I hardly think that is what you are after. Be more specific and you're bound to get more help.
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
i meant :
the program takes the input a b (two inputs) and the rest it generates the combinations with a b - - -.(string combination of length 5 with first two given or inputted.)
and also if s and t are the inputs it creates the combinations with s t - - -.
without repetition means if a b c d e is one of the output a b d c e can't be the output.
and the program should generate each and every combination of the input.
like a and b are inputs then,
a b c d e
a b d e f
.
.
.
etc.
thanking you
|
|
|
|
|
well, just generate a random letter between a and z, repeat until it is not one of your 2 input letters, and add to the string ( repeat 3 times for the 3 letters ).
or do the letters "c d e" or "d e f" are sequential ?
can you have :
a b z g r
?
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
yeah
we can have a b z g r but if a b z g r comes first then a b g r z cannot occur.
or first can you please give me the loop code for generating the sequence of strings.
like a b c d e
...
..
..
a b x y z .
with each and every combination.
i am not that good in programming.
so can you please help me generating the string sequence.
thanking you
|
|
|
|
|
You're still not making any sense. What is the correlation between the two inputs and the final output? Do the two inputs always get appended to the front of the output? What would "c n" yield?
kamal_aluri wrote: ...the program should generate each and every combination of the input.
Which looks like what? For your "a b" example, the six outputs are:
a b c d e
a b c e d
a b d c e
a b d e c
a b e c d
a b e d c
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
he just want 3 other letters ( different than the 2 original ones ).
I don't think there is any correlation between the 2 input values and the 3 others (except they must be different )
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
i am sorry for being unclear.
the thing is there are 26 alphabets and the inputs should be 2(a b or b c or whatever)
and the program should generate strings of length 5 starting with given input.(a b or whatever)
that is combinations of a b - - -
the three -'s should be filled with the string combinations(from the remaining 24 alphabets) of length 3 and other than given input (a b in this case.)
thanking you.
|
|
|
|
|
This should work:
#include <string>
#include <algorithm>
std::string GenerateString(const std::string& input)
{
std::string output("abcdefghijklmnopqrstuvwxyz");
for(int i=0; i<2; i++)
{
std::remove(output.begin(), output.end(), input.at(i));
}
std::random_shuffle(output.begin(), output.end());
output.resize(3);
output.insert(0, input);
return output;
}
[edit]of course, you better check the size of input to make sure it has 2 chars in it, else you'll get an exception. [/edit]
~Nitron.
ññòòïðïðB A start
-- modified at 16:44 Tuesday 7th February, 2006
|
|
|
|
|
Your loop should probably look something like:
char Result[7];
// assuming result[0] and Result[1] have already been filled
Result[6] = '\0';
for (Result[2] = 'a'; Result[2] <= 'z'; Result[2]++)
{
if ( Result[2] != Result[0]
&& Result[2] != Result[1])
{
for (Result[3] = Result[2]; Result[3] <= 'z'; Result[3]++)
{
if ( Result[3] != Result[0]
&& Result[3] != Result[1]
&& Result[3] != Result[2])
{
........ etc.
printf ("%s\n",Result);
}
}
}
}
Didn't yet think this through completely, but its a start.
William
|
|
|
|
|
Keep an array of alphabet, and take two letters as input.
And then create a copy of the removed letters and store it as an array.
then, use a combination generator (you can google for it), a JAVA implementation can be found below. (The only problem you would face to port this code to C++ or C is the BigInteger class, you might use __int64 for factorial calculation. you need to be able to assign 24! in that implementation, the int type might also work, you can check it by calculating 24! .
http://www.merriampark.com/comb.htm[^]
however, if you consider comb(n,r) = n!/(n-r)!r! then 24!/(24-3)!3! = 24.23.22/3! so if you can modify the JAVA implementation likewise then you do not need to take care of bounds for 'int' for this particular problem.
this might be one of solutions, and thought out while writing.
Bekir.
|
|
|
|
|
thanx to everybody who replied for my question.
i got it and i'll paste the program when it's in shape.
thanx guys.
|
|
|
|
|
Hi again
I am embarrassed to ask this question, but hey, if you dont ask, you dont get to know...
I have an application written by others that generates an Edit Box by using the following code:
HWND hwndEdit;
hwndEdit = CreateWindowEx(WS_EX_CLIENTEDGE, _T("EDIT"), "",
WS_CHILD|WS_VISIBLE|WS_TABSTOP,
20,25,200,23,
hWnd, NULL, hInstance, NULL);
I now want to add to the program by including a ListBox. Can I do this by:
HWND hwndList;
hwndList = CreateWindowEx(WS_EX_CLIENTEDGE, _T("LISTBOX"), "",
WS_CHILD|WS_VISIBLE|WS_TABSTOP,
20,25,200,23,
hWnd, NULL, hInstance, NULL);
(changing the co-ords, of course)
This does appear to work, but I cant work out how to add strings to the ListBox - can anyone help, or show me what I am doing wrong
Thanks for any help that you can give to a newbie!
Mike
|
|
|
|
|
Send the listbox the LB_ADDSTRING message.
char szMyString[64];
strcpy(szMyString, "This is my string.");
lResult = SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)szMyString );
The string should end up in the list box.
See other LB_??? messages for the other actions you can perform on the listbox.
People that start writing code immediately are programmers (or hackers), people that ask questions first are Software Engineers - Graham Shanks
|
|
|
|
|
Your a Star!
I have just tried that and it works - simple!
Thank you very much
Mike
|
|
|
|
|
|
just a guess, why are you passing CClassBase const& parameters instead of the common const CClassBase& ... i don't remember if it changes something, so i wondered about that...
any reason ?
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VCalc 3.0 soon...]
|
|
|
|
|
|
badkarma pointed a good point. however, instead of redefining the methode for the specialization, what happens if you change your
CClassBase fun(CClassBase const& X, CClassBase const& Y){...} into
const CClassBase& fun(CClassBase const& X, CClassBase const& Y){...}
.....?
_Russell_ wrote: I don't know if is possible that I can use this operator ("=") defined into the parent class using derivates object
thanksfully to OOP paradigm, such a thing is possible ! a child class instance remains an instance of the base class type... so pointing childs with a base class pointer works (but it has to be pointer - or reference, but not variables)...
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VCalc 3.0 soon...]
|
|
|
|
|
Yes,
the point is that the child object could have some variable (members) more than the parent -> and here there was problems!! (I think)
thanks anyway
Have a nice code day
|
|
|
|
|
i think using dynamic_cast<>() on the return value of fun() might have worked too, without overloading the specialization within the child class...
Z = dynamic_cast< CClassDouble > (fun(X, Y));
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VCalc 3.0 soon...]
-- modified at 11:29 Tuesday 7th February, 2006
|
|
|
|
|
I believe the problem lays with the function fun
The function fun returns a CClassBase object and not a CClassDouble object.
The compiler can't upcaste the object from CClassBase to CClassDouble
this can be solved by adding a default constructor to the class CClassDouble
class CClassDouble: public CClassBase<double>{
public:
CClassDouble(const CClassBase<double>& R) {...}
...
}:
Hope that this will solve your problem
codito ergo sum
|
|
|
|
|
Thanks,
there was a cast problem!;)
It is only a little bit strange that it isn't automatically converted (they are exactly the same thing)
So, bye for 3 weeks (only answers!)
And, olso this time, a 5 for you.
Have a nice code day
|
|
|
|
|
hi,
its not that strange since the lower class (CClassBase ) cannot know all the extra members that need to be initialized when creating a CClassDouble object.
Don't worry about asking quistion, especially those about templates,
there my favorite ones
codito ergo sum
|
|
|
|
|
_Russell_ wrote: CClassBase fun(CClassBase const& X, CClassBase const& Y){...}
You can't write that. CClassBase is a template class, you need to supply a template parameter:
template <class T> CClassBase<T> fun(const CClassBase<T>& X, const CClassBase<T>& Y){} The only time you write plain CClassBase is in the ctor and dtor.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
How can I build an ActiveX-DLL in Visual Studio 6.0? I have especially a problem in constucting a new method, which is an ActiveX-Component. There's a tool called "ActiveX Testcontainer" in which I should see my methods, but I don't. What's wrong?
I created a project with the "ActiveX-Control-Wizard" and added a "Member-Function". This isn't shown as a method in the "ActiveX Testcontainer".
Thanks for your help!
Markus
Do also have a look at my earlier Thread:
http://www.codeproject.com/script/comments/forums.asp?forumid=1647&fr=26#xx1362023xx[^]
|
|
|
|