Garlic and Spices -help

Description
Garlic, a wanderlust since she was 16, has been traveling for a living. She particularly likes driving to places and
practically spends about 80% of her life on the road.
One day as Garlic was exploring the beauty of Rio de Janiero, she met a guy named Hilario.
Hilario loves big bikes and spends most of his time with it. Meeting Garlic, Hilario decided to name his big bike after her.
Free as they are, after skydiving, they rode Hilario's big bike to the weirdest towns in the world.
Be their travel guide and help them identify various routes they can take from one town to another.
Input Format
The input file begins with an integer J, where 0 < J <= 100, that defines the number of test cases. Each test case
consists of three lines. The first line contains a positive integer N <= 500, that specifies the number of towns. The
second line is a sequence of towns Town1 to TownN, each separated by a comma. The last line contains N-1 positive
integers indicating the number of roads one could take from Town1 to Town2, Town2 to Town3, ... , TownN-1 to TownN.
Output Format
For each test case, output the possible routes Garlic and Hilario could take to travel from Town1 to TownN.
Last edited on
Sample Input
3
4
Pie Town, Little City, Sodaville, Winterville
1 1 1
3
Bummerville, Squabbletown, Spooky Mountain
2 3
4
Mystic, Wahoo, Lame Deer, Cheesequake
2 2 3

Sample Output

Pie Town->Little City_1; Little City->Sodaville_1; Sodaville->Winterville_1

Bummerville->Squabbletown_1; Squabbletown->Spooky Mountain_1
Bummerville->Squabbletown_1; Squabbletown->Spooky Mountain_2
Bummerville->Squabbletown_1; Squabbletown->Spooky Mountain_3
Bummerville->Squabbletown_2; Squabbletown->Spooky Mountain_1
Bummerville->Squabbletown_2; Squabbletown->Spooky Mountain_2
Bummerville->Squabbletown_2; Squabbletown->Spooky Mountain_3

Mystic->Wahoo_1;Wahoo->Lame Deer_1; Lame Deer->Cheesequake_1
Mystic->Wahoo_1;Wahoo->Lame Deer_1; Lame Deer->Cheesequake_2
Mystic->Wahoo_1;Wahoo->Lame Deer_1; Lame Deer->Cheesequake_3
Mystic->Wahoo_1;Wahoo->Lame Deer_2; Lame Deer->Cheesequake_1
Mystic->Wahoo_1;Wahoo->Lame Deer_2; Lame Deer->Cheesequake_2
Mystic->Wahoo_1;Wahoo->Lame Deer_2; Lame Deer->Cheesequake_3
Mystic->Wahoo_2;Wahoo->Lame Deer_1; Lame Deer->Cheesequake_1
Mystic->Wahoo_2;Wahoo->Lame Deer_1; Lame Deer->Cheesequake_2
Mystic->Wahoo_2;Wahoo->Lame Deer_1; Lame Deer->Cheesequake_3
Mystic->Wahoo_2;Wahoo->Lame Deer_2; Lame Deer->Cheesequake_1
Mystic->Wahoo_2;Wahoo->Lame Deer_2; Lame Deer->Cheesequake_2
Mystic->Wahoo_2;Wahoo->Lame Deer_2; Lame Deer->Cheesequake_3


This is not a place for just dumping homework questions and expecting people to write them for you. We'll help you with specific issues or questions you have, but we're not going to write your code for you.
i know iam not asking for a code., iam asking for an idea im almost finish solving it, i just forgot to wirite my question....

what would be the best way to display the ouput?

i tried using nested loops but the case is the number of towns is not fix,m and the number of nested loops should vary too...

is there any function like recursion?
Topic archived. No new replies allowed.