Ask your own question, for FREE!
Computer Science 15 Online
OpenStudy (anonymous):

need help with a computer science problem (c++)........ Write a program that reads three strings and displays the strings in all possible sequences, one sequence per output line. Display the symbol * between the strings on each line.

OpenStudy (anonymous):

what have you done so far?

OpenStudy (anonymous):

this is complex

OpenStudy (anonymous):

3 words or all letter combinations?

OpenStudy (anonymous):

it says three strings, so probably just 3 "words", however strings is not necessary a word but it doesn't matter

OpenStudy (anonymous):

I"m gonna have to back out of this one its time for dinner off the top of my head without writing any code i believe there are a minimum of 9 combinations.

OpenStudy (anonymous):

I'd make a sudo logic table with as many combinations as i can think of and work off that.

OpenStudy (anonymous):

no it's probably 6 first second third first third second second first third second third first third first second third second first however it doesn't say if you need to always use all of them, e.g. idk if you can print just one string or two strings

OpenStudy (anonymous):

def permute(head,tail=[]): if len(head) == 0: printit(tail) else: for i in range(len(head)): permute(list(head[0:i])+list(head[i+1:]), list(tail)+[head[i]]) def printit(lst): for i in range(len(lst)-1): print lst[i], '*', print lst[-1] if __name__ == '__main__': permute(['this','is','test']) permute(['this','is','much','larger','test']) permute(['this']) permute(['and','another']) #since this is Python, the obligatory one-liner, if you import itertools is: #for w in list(itertools.permutations(['this','is','test'])): printit(w)

OpenStudy (anonymous):

this is called a Permutations Algorithm, you have to search for it.

OpenStudy (anonymous):

It uses lots of toys from C++ standard library though, so you might want to check out the entry on C: http://rosettacode.org/wiki/Permutations#C

OpenStudy (anonymous):

agdgdgdgwngo .....thanks for those links permutations are a new method/concept for me but it mad my head spin with possible uses. Thanks again~!

OpenStudy (anonymous):

thank you agdgdgdgwngo that was really helpfull, thanks all for helping

OpenStudy (anonymous):

I think since there are only 3 strings they want them to do it manually, but yeah using that code is better since it works for all cases but even more better would be to create that code yourself

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!