Conversion of Ruby-code to c/c++ code :: URGENT Plz help

Hi… I urgent require to convert the following ruby-code to c/c++ code.
If some-one have both the knowledge …plz help me… At least give me
some algorithm to it… IT’s ABOUT THE MORSE-CODE CONVERSION TO STRINGS
IN ALPHABETICAL ORDER


#!/usr/bin/env ruby -wKU
require “set”
MORSE_LETTERS = %w[.- -… -.-. -… . …-. --. … … .— -.- .-…

-. — .–. --.- .-. … - …- …- .-- -…- -.-- --…]
ENCODINGS = Hash[*MORSE_LETTERS.zip((‘A’…‘Z’).to_a).flatten]

def morse_decodings(word)

iterate through matching prefixes

ENCODINGS.select { |p,l| p == word[0,p.size] }.map do |
prefix,letter|

# gather decoded suffixes for the current prefix
suffixes = morse_decodings( word[prefix.size,word.size] )

# append decoded suffixes to decoded letter
suffixes.empty? ? letter : suffixes.map { |s| letter + s }

end.flatten
end

decodings = morse_decodings(readline.chomp).sort

puts “All Possible Decodings:”
decodings.each { |e| puts e }

Homework?

No… its for company-question … i have to understand this code asap…
also i am new to ruby…

Subject: Re: Conversion of Ruby-code to c/c++ code :: URGENT Plz help
Date: Mon 14 Jan 13 10:12:18PM +0900

Quoting Nilesh S. ([email protected]):

No… its for company-question .

Funny. A company dabbling with Morse code in the 21st century…
I may want to send them a CV…!

Carlo

Carlo E. Prelz wrote in post #1092231:

Subject: Re: Conversion of Ruby-code to c/c++ code :: URGENT Plz help
Date: Mon 14 Jan 13 10:12:18PM +0900

Quoting Nilesh S. ([email protected]):

No… its for company-question .

Funny. A company dabbling with Morse code in the 21st century…
I may want to send them a CV…!

Carlo

I just want to know the algorithm for the code… rest i’ll do it…

Peter H. wrote in post #1092234:

If you know neither Ruby or C++ then no one can help you. The job you
are
trying to get will have much harder problems than this interview
question.

i know C++ but don’t know the algorithm of morse-code
conversion…
finally i found the program in RUBY language… but i don’t understand
it… explaining this code steps-by-steps will be grateful …

plz help…

Hi,

Is this a joke? My advice: read a Ruby book to get familiar with the
Ruby language.

Thiel

Op 14-1-2013 14:04, Nilesh S. schreef:

If you know neither Ruby or C++ then no one can help you. The job you
are
trying to get will have much harder problems than this interview
question.

So you also do not know how to use Google?

“convert morse code to text in C++”

It takes a stream of . and - and sees what it might be:

$ ruby morse.rb
…-…-…-…
All Possible Decodings:
EAEAEAEE
EAEAEAI
EAEAEED

Of course you could run the program and find out for yourself.

i know C++ but don’t know the algorithm of morse-code
conversion…

Best regards:

Z.