I need anagram logic for a 5 lines passage entered by user. In java. Pls help asap.
pls give the ques link…and also pls show some signs of effort that u may have taken to solve…!!!
i cannot apply the code due to some reasons…but i have reached till the point that accepting passage from user and breaking the words and storing it in variable array…but frankly i am really unaware of anagram logic so i need the help…
can u give the link to the problem statement…or maybe post the problem statement in the ques above…is it related to TCS practice contest???
brother its against the policy as its part of a contest so i cant post link…the problem statement is I have to take statement from user with ‘w’ words where (w<5000)…i need to check anagrams sequentially and print the anagram as it occurs in sequence…and if same anagram comes twice then it should not print second time…
dude…it is a practice ques…not the real contest…i myself had posted a ques for this problem…i was very close to the soln but got a WA…http://discuss.codechef.com/questions/19730/anagram-wa
ahh…great…actually i thought not to take chance…anyways i wouldnt be able to send link as round is over already…between any progress in it??
My logic was first split the strings into individual parts, then make a hash table of size 130. Basically a counter for the number of occurences of each character. I then hash each string into the table based on ascii value of its characters. The hash table of size 130 is required because of presence of punctuation marks however when comparing, only numbers and characters are to compared.
Then its a O(n^2) algorithm where i start from 1st string and compare hash table of this with other strings if length is equal and add it to an array of anagrams for this word.iterating over the whole length would give all anagrams.
It is also important to check if the new string found is not present in the array of anagrams you create.
Once an anagram is found i set to empty string to avoid future comparisons.
Inspite of all this i still got ‘Almost there, try some more’!!!
Biggest problem is handling cases like “dont’s” and something like “stond”. I did write conditions to check all those still no success. I was implementing in python so some things might be tougher to implement in C or C++ but this algorithm would work.
Another algorithm is calculating a unique hash value of each string and then using hash values for comparisons. However this would involve designing a good hash function and taking care of all special cases.
hello sir…can you post me the code itself?
will give you a link today evening.
actually i was in need urgently…as its a part of competition and deadline is few hours so…
Even i am participating in the contest and it was just a practise question. mastering one question wont help in any way. Better revise other important concepts. i would have posted the code but i dont have it with right now. sorry man, cant help.
Which contest is this ? Where is it getting organized ? Can you give a link . Maybe this contest is over , but want to know where it was being organized .
yeah yeah i understand…but i was thinking to get hands on with this code…so i needed
the question is for TCS code-vita but it is only for college students and 1st round begins today at 3.
First 2 rounds are online rounds, then onsite finals at TCS office. These were just a few practice questions they had given
you too taking part in competition?
yes, even i am participating