|
There is nothing random about getting all the possible permutations of a sequence: it's a systematic process.
Steve
|
|
|
|
|
i cant get it...explain more detail pls..
|
|
|
|
|
Imaging you have a dice with 100 sides each labeled with a number. If you want to make a list of all the numbers how do you proceed? One way would be keep rolling the dice and if the number you roll is not on your list you add it. This is very inefficient and non-deterministic however. A simper way would be just to inspect every side. This is similar to the problem you’re having. Using a random shuffle in a loop is not a good way to get every permutation of a sequence: although eventually it will product every combination.
Steve
|
|
|
|
|
is there any othe methods to solve the problem...if i cannot use random shuffle what i must use..
|
|
|
|
|
Maxwell is correct, use next_permutation . The first permutation is the sorted one so you should do this first: sort(s.begin(), e.end());
Steve
Steve
|
|
|
|
|
Hi Steve,
Should we provide a working sample code for THIS[^]?
Maxwell Chen
|
|
|
|
|
I just did - I want this thread to end.
Steve
|
|
|
|
|
std::next_permutation(it.begin(), it.end());
Maxwell Chen
|
|
|
|
|
i tried dis b4...but still the same result...i want all the possible integer randomisation..
for example...
my input file contents... 1234
my output must give the result as
4321
2341
2314
4213
1243
..
..
..
and so on...
all the possible randomised shuffling...
icant get it....is there any possible way..
|
|
|
|
|
If you had of tried it it would have worked. Here's a program which demonstrates this technique:
------------
// Console.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(int argc, char* argv[])
{
string s("1234");
sort(s.begin(), s.end());
do
{
cout << s << endl;
}
while ( next_permutation(s.begin(), s.end()) );
return 0;
}
Steve
|
|
|
|
|
Hey all im making a game for school on MFC and im having trouble making it so when I press W,A,S, or D it will move my character... I know how to make him move if I press the arrow keys (previous game):
case VK_DOWN: //IF DOWN BUTTON IS PUSHED
{
}
I have already tried VK_A, any help would be appreciated!
Thanks
|
|
|
|
|
|
I think you need this
case VK_DOWN:
case 'S':;)<br />
{<br />
...<br />
break;<br />
}<br />
<br />
case VK_UP:
case 'W':;)<br />
{<br />
...<br />
break;<br />
}<br />
<br />
...
|
|
|
|
|
why small ball jump, background bmp jump too?
I write the code.
I want to ball jump, backgroud bmp do not jump?
Has the solution?
thanks.
source code:
http://ComAndATL.googlepages.com/Game.part1.rar
http://ComAndATL.googlepages.com/Game.part2.rar
If you solution, may the code which solution send my email zhmster@gmail.com.
very very thanks you !
alantop
-- modified at 15:34 Sunday 7th May, 2006
|
|
|
|
|
update!
alantop
-- modified at 4:58 Monday 8th May, 2006
|
|
|
|
|
I need to convert an unsigned int to a char*.How can I do it??
Thanks in advance!!
|
|
|
|
|
#include <stdlib.h>
#include <stdio.h>
void main()
{
unsigned int i = 123;
char p[100];
itoa(i, p, 10);
printf("%s\n", p);
}
alantop
|
|
|
|
|
alan top :
<br />
void main()<br />
{<br />
unsigned int i = 123;<br />
char p[100];<br />
<br />
itoa(i, p, 10);<br />
printf("%s\n", p);<br />
}<br />
-----------and-----------------
unsigned int a=100;
char *buffer;
buffer=(char*)LocalAlloc(LPTR,20);
itoa(a,buffer,10);
unsigned int c;
c=atoi(buffer);
LocalFree(buffer);
|
|
|
|
|
Here is another way to do this
unsigned int i=100;
char p[10];
sprintf(p,"%u",i);
cout<<p;
Knock out 'T' from CAN'T ,
You 'CAN' if you think you 'CAN'
|
|
|
|
|
You can Also use Reinterpret_cast
Thanks & Regards
Banks
|
|
|
|
|
I create a client socket class that derived from CAsyncSocket, it connects to server ok. When server disconnects then nothing wrong, but when client side closed the connection then it's got a problem: sockcore line 482 (and 442), those lines are:
ASSERT(CAsyncSocket::LookupHandle(hSocket, bDead) != NULL);(line 482)
ASSERT(CAsyncSocket::LookupHandle(hSocket, bDead) != NULL);(line 442)
Can any one tell me why it happen and how to handle it?
Just a newbie
-- modified at 14:11 Sunday 7th May, 2006
|
|
|
|
|
XStress wrote: Can any one tell me why it happen
When one side of a socket connection is closed the remote stack is notified and the state of the socket handle is updated. So "if" the other side calls close the handle is not in a valid state to be closed.
XStress wrote: how to handle it?
That is up to you to determine based on the applications use model. One option is to use AsyncSelect[^] to be notified when the other socket closes the connection.
"What classes are you using ? You shouldn't call stuff if you have no idea what it does" Christian Graus in the C# forum
led mike
|
|
|
|
|
It's not really close to my problem. In my situation, after client successfully connect to server, call Close() function will make the program crash. It's strange because it doesn't happen in server side and in other example i saw.
If problem is remote stack then when client close, the side that encounter problem is server side right??
Just a newbie
|
|
|
|
|
XStress wrote: It's not really close to my problem.
Sorry. I misunderstood the first post.
It does seem however that your client side socket is not in a connected state when you are trying to close it. Or the MFC Thread Local Storage does not contain information for that Socket. That is why the assert is firing. Based on what you posted there is no way to determine why. That assert is letting you know that the MFC collection of opened or in their language, "Not Dead", sockets does not contain the socket handle you are attempting to close.
"What classes are you using ? You shouldn't call stuff if you have no idea what it does" Christian Graus in the C# forum
led mike
|
|
|
|
|
I wrote some code using Visual Studio.net with MFC and it is easy to add stuff to the dialog box. But, I can't remove anything like an edit box etc. when there was an associated var name in the code. I get run time errors or if bad enough, I get severe compile errors. I tried doing it with just one litle window and I get runtime errors. How in the world do you remove something you do not want anymore. I removed everything that was associated with it I thought. When I removed from the resource.h file, thank god I had backed it up. I had to abort and reload the original code, it was so screwed up.
Help would be greatly appreciated.
Dan Martin
|
|
|
|