7 Replies - 8843 Views - Last Post: 01 August 2007 - 05:25 AM Rate Topic: -----

#1 ships04  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 30-July 07

program to print all sequences of an alphabet

Posted 30 July 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.

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??

Is This A Good Question/Topic? 0
  • +

Replies To: program to print all sequences of an alphabet

#2 imamkomc  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 64
  • Joined: 09-May 07

Re: program to print all sequences of an alphabet

Posted 30 July 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.
Was This Post Helpful? 0
  • +
  • -

#3 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5388
  • View blog
  • Posts: 27,382
  • Joined: 10-May 07

Re: program to print all sequences of an alphabet

Posted 30 July 2007 - 06:24 AM

View Postships04, on 30 Jul, 2007 - 02:53 AM, said:

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?
Was This Post Helpful? 0
  • +
  • -

#4 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: program to print all sequences of an alphabet

Posted 30 July 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.
Was This Post Helpful? 0
  • +
  • -

#5 ships04  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 30-July 07

Re: program to print all sequences of an alphabet

Posted 30 July 2007 - 05:57 PM

View Postimamkomc, on 30 Jul, 2007 - 05:30 AM, said:

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??

View PostAmadeus, on 30 Jul, 2007 - 06:34 AM, said:

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...
Was This Post Helpful? 0
  • +
  • -

#6 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: program to print all sequences of an alphabet

Posted 31 July 2007 - 06:05 AM

Are you allowed to use the functions available from the STL?
Was This Post Helpful? 0
  • +
  • -

#7 ships04  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 30-July 07

Re: program to print all sequences of an alphabet

Posted 01 August 2007 - 12:57 AM

View PostAmadeus, on 31 Jul, 2007 - 06:05 AM, said:

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


You mean standard library functions right? Yes, we are allowed to use those...
Was This Post Helpful? 0
  • +
  • -

#8 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: program to print all sequences of an alphabet

Posted 01 August 2007 - 05:25 AM

Then check out next_permutation() from the <algorithm> header...it will do what you require.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1