Link to home
Start Free TrialLog in
Avatar of Jack020800
Jack020800Flag for India

asked on

Complex String Manipulation program

Hi,
I need the help with the logic for below program -
there is a txt file containg some data on each line as follow:

First line: T (i.e.Number of test cases)
Secod line : M (i.e. Number of words or lines to follow ion each case)
Third onwards: String data in lower letters only..

Ex.
2
3
map
manip
hashcode
4
deltas
alphag
szeta
gamma
 
output:
false
true

like the txt file above.
Now the logic need to read the file and if the start letter of a word is end letter of some other word in the same test case.then the output true or else false.
Like in above example there are 2 test cases and 3 strings in 1st case, namely 'map','manip', and 'hashcode'.The last case has 4 strings.
If the words in each test case can be arranged like
deltas szeta alphag gamma
i.e. the start of each string is the end of some other and they can be arranged in the series like above!then its true otherwise false.
If can get the help for for both C++ and java it wil be nice

Thanks & regards,
Avatar of Infinity08
Infinity08
Flag of Belgium image

>> If can get the help

What kind of help ?
Avatar of a_b
a_b

good one
ASKER CERTIFIED SOLUTION
Avatar of a_b
a_b

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi a_b, make sure to read the homework rules for Experts Exchange before posting complete code samples. This does appear to be a homework related question.
the code in http:#a24466919 causes an ArrayIndexOutOfBoundsException when given onput like
2
ab
ba
It also gives different answers for

4
za
ab
ac
ca

and

4
za
ac
ab
ca
Avatar of Jack020800

ASKER

Hi a_b,
love u so much for this nice code!Although i executed it just manually, I am happy.And for the helpfull comments from "ozo", I appreciate it and I will think further for the new version for the code to handle this bug!
For all those worrying for 'whether it is homework problem', so its not actually, I am IT professional.
Thanks for the comments guys.Now let me check the code at home and if enhancement is possible by me.

Regards,