Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,178 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,997 people online right now. Registration is fast and FREE... Join Now!




program to print all sequences of an alphabet

 
Reply to this topicStart new topic

program to print all sequences of an alphabet

ships04
30 Jul, 2007 - 01:53 AM
Post #1

New D.I.C Head
*

Joined: 30 Jul, 2007
Posts: 3


My Contributions
Hi
OK heres my assignment question- Write a program that, given n and alphabet Z as inputs, outputs all strings of length n over the alphabet Z.

now alphabet here means a string array where for example Z = {a, c} can be an alphabet of 2 symbols and if I want to out all the strings of length 3, this is what I should get (9 strings in total) -
aaa
aac
aca
caa
acc
cac
cca
ccc

Now i dont have any code as I am still struggling with concepts... First idea I had in mind was like to do a matrix of width n and length = total number of strings.... but, then how do I fill up the matrix??

I have no idea how to approach this problem - there is another idea i came up with which was like initialising the sequence of length n to the first symbol of the alphabet ..But again how would I come around to changing the sequence - I cant figure it out.. any ideas??
User is offlineProfile CardPM
+Quote Post

imamkomc
RE: Program To Print All Sequences Of An Alphabet
30 Jul, 2007 - 04:30 AM
Post #2

D.I.C Head
Group Icon

Joined: 9 May, 2007
Posts: 62


Dream Kudos: 225
My Contributions
Hi ships04,
I understood you problem, but if you not effort write your code program.
i dont know where erors getting.
I think total of all possible string output is result nxn.


User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Program To Print All Sequences Of An Alphabet
30 Jul, 2007 - 05:24 AM
Post #3

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,451



Thanked: 66 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
QUOTE(ships04 @ 30 Jul, 2007 - 02:53 AM) *

Hi
OK heres my assignment question- Write a program that, given n and alphabet Z as inputs, outputs all strings of length n over the alphabet Z.

By alphabet, do you mean, litterly the alphabet, or a given string, or preset text?
So the program will be input a number & a letter. What is it checking these arguments against?

User is online!Profile CardPM
+Quote Post

Amadeus
RE: Program To Print All Sequences Of An Alphabet
30 Jul, 2007 - 05:34 AM
Post #4

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,226



Thanked: 37 times
Dream Kudos: 25
My Contributions
I think he means to define alphabet by the array Z, and provide variable n which would represent the number of characters in the string,and get all the permutations against that.

In the example above, Z is the character array, while n would be three. Z could be any number of letters.n could be any integer.
User is offlineProfile CardPM
+Quote Post

ships04
RE: Program To Print All Sequences Of An Alphabet
30 Jul, 2007 - 04:57 PM
Post #5

New D.I.C Head
*

Joined: 30 Jul, 2007
Posts: 3


My Contributions
QUOTE(imamkomc @ 30 Jul, 2007 - 05:30 AM) *

Hi ships04,
I understood you problem, but if you not effort write your code program.
i dont know where erors getting.
I think total of all possible string output is result nxn.


Hi I cant start writing the code if I dont know what I am doing... I mean I need to work out some kinda algorithm or psuedocode first - that is where I am stuck... I have mentioned a couple of my ideas but those ideas dont work - i mean they dont make sense so I am asking if you guys have any ideas??

QUOTE(Amadeus @ 30 Jul, 2007 - 06:34 AM) *

I think he means to define alphabet by the array Z, and provide variable n which would represent the number of characters in the string,and get all the permutations against that.

In the example above, Z is the character array, while n would be three. Z could be any number of letters.n could be any integer.


yea your write - thats exactly what I mean, Z could be any kinda array and of any length - it would be some random numbers or characters or symbols like Z = { 1, 5, 7} or Z = { $, #, /, 8 }... and output shud be the permutations... by the way i am a female...
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Program To Print All Sequences Of An Alphabet
31 Jul, 2007 - 05:05 AM
Post #6

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,226



Thanked: 37 times
Dream Kudos: 25
My Contributions
Are you allowed to use the functions available from the STL?
User is offlineProfile CardPM
+Quote Post

ships04
RE: Program To Print All Sequences Of An Alphabet
31 Jul, 2007 - 11:57 PM
Post #7

New D.I.C Head
*

Joined: 30 Jul, 2007
Posts: 3


My Contributions
QUOTE(Amadeus @ 31 Jul, 2007 - 06:05 AM) *

Are you allowed to use the functions available from the STL?


You mean standard library functions right? Yes, we are allowed to use those...
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Program To Print All Sequences Of An Alphabet
1 Aug, 2007 - 04:25 AM
Post #8

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,226



Thanked: 37 times
Dream Kudos: 25
My Contributions
Then check out next_permutation() from the <algorithm> header...it will do what you require.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 12:58AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month