Help, good day. i'm trying to make a program in c which basically jumble possible combinations of a given word for example
i input: CAR
RAC
ACR
CRA
...
..
..
How do i do this? Need help please.
6 replies to this topic
#1
Posted 24 June 2010 - 07:32 AM
|
|
|
#2
Posted 24 June 2010 - 07:50 AM
Here's one solution for that (pseudo code):
Greets,
artificial
string InputString; //String that contains your input; in this case: CAR
array OutputBuffer[size of InputString];
variable a = 0;
while(all elements of InputBuffer != '$')
{
variable n = random integer number between 0 and size of InputString;
if(InputString[n] != '$') //$ is used to show the program that this element is already stored in OutputBuffer
{
OutputBuffer[a] = InputString[n];
a++;
InputString[n] = '$';
}
}
Print(OutputBuffer);
Greets,
artificial
#3
Posted 24 June 2010 - 07:54 AM
hmm i think this can be done the easy way using pointers can you sow me?
#4
Posted 24 June 2010 - 08:02 AM
twogreenarrows said:
hmm i think this can be done the easy way using pointers
I just said that this is one solution. Of course there are more and some of them might be better. ;)
Actually, my example uses pointers. In fact, a string is a pointer to the first char of an array that is zero terminated.
Greets,
artificial
EDIT: Tell me your basic idea. Then I (and the others) can give you concrete tips.
Edited by artificial, 24 June 2010 - 08:04 AM.
EDIT
#5
Posted 24 June 2010 - 08:06 AM
Input:
car
possibilities:
dan
dna
nda
nad
and
adn
Thank You!
like that no functions, printf, scanf, just simple things okay thanks!
car
possibilities:
dan
dna
nda
nad
and
adn
Thank You!
like that no functions, printf, scanf, just simple things okay thanks!
#6
Posted 24 June 2010 - 08:23 AM
Yeah, I understand what the program is supposed to do. You just have to swap the chars' locations until you have the desired result.
My code is one example for that (and indeed an inefficient one).
Maybe I just don't get it. I hope that the other members can help you. :)
Greets,
artificial
PS: I don't think that there's a reasonable function that creates "dan" from the word "car". ;)
My code is one example for that (and indeed an inefficient one).
Maybe I just don't get it. I hope that the other members can help you. :)
Greets,
artificial
PS: I don't think that there's a reasonable function that creates "dan" from the word "car". ;)
#7
Posted 24 June 2010 - 09:23 AM
This has already been answered here - String Permutation.
A conclusion is where you got tired of thinking.
#define class struct // All is public.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









