English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Ok here is the brief decription:
if
input : 1 2-7 8-12
then the output should be
output: 1 2 3 4 5 6 7 8 9 10 11 12
now the input doesn;t have to be in a sequence,
for example
input : 1 5-7 8-11
then the output should be
output : 1 5 6 7 8 9 10 11
basically it expands the integers represented by '-',but prints out the other integers just as it is.
Can anybody give me a hint or a sample prog. how to implement this ?
Thank you.

2007-03-16 08:11:56 · 3 answers · asked by vishal1987 1 in Computers & Internet Programming & Design

3 answers

1. take the input string and tokenize it by " ". This'll give you an array of "1" "2-7" "8-12"
2. for each element in this array:
if the string does not have "-" then print it out
else tokenize by "-" and convert to integer so you'll have an array of startpoint=2 and endpoint=7 (in the case of "2-7")
for(i=startpoint; i

2007-03-16 08:18:26 · answer #1 · answered by Anonymous · 1 0

Agree with "Buck Boy" and support some how what "icnintel" in such people should show hints and pseudo codes, but it angers me seeing people answering straight with full source code.

Hint:
1.) Read the whole as a string
2.) tokenize the string by a delimited by spaces
3.) for each tocken display the content unless it contains a dash
4.) if dashes were detected, detect the character before and after the dash, convert them into integers and loop to display them

Good luck

2007-03-16 15:36:53 · answer #2 · answered by Coosa 2 · 0 0

Sample programs, NO.
Hints, YES.
Hint: Read your textbook!

BTW, I think it should be a policy on these forums not to answer homework questions as posted by you. You have shown no attempt at starting this but is already asking for help.
Come up with a solution and if you are stuck we'll answer your questions but don't expect people to *do* your work for you. It's highly unethical.

2007-03-16 15:21:03 · answer #3 · answered by Buck Boy 2 · 1 1

fedest.com, questions and answers