+ 2

Unable to prepare logic for string manipulation

Hi, Need to develop a logic to find out common string between two strings: Below is my code snippet for same, but I am unable to put a logic for same.. Looking for hint from you guys...: https://code.sololearn.com/cLk0F4nVop3k/?ref=app Input 1 : KETAN , TALNE : common string is TAN, not ETAN as E is not having proper order in both string. Desired output is 3. Input 2 : AB, BA : common string is eitger of B or A and hence, output is 1. Input 3 : NAHAS, NDAN : Common string is NA and output should be 2. Input 4 : ASD, FGH : common string doesn't exist and output should be 0. Any thoughts will be of great help...

2nd Aug 2018, 3:18 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
27 odpowiedzi
+ 2
submitted... I am not sure whether this will get approved or not..
3rd Aug 2018, 12:17 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 2
https://code.sololearn.com/c35rM92Bnk7Q/?ref=app ok but in this one problem that strlen is not working.
7th Sep 2018, 3:21 PM
Ronald
+ 2
pettemsrikanthvarma aapprecitate your efforts but it is not giving proper expected output.. just check input case 1 in my description of question... output is 4 instead of expected output 3
7th Sep 2018, 3:31 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 2
https://code.sololearn.com/c35rM92Bnk7Q/?ref=app once check it I hope this code will reach your expectations. thank you.
8th Sep 2018, 1:00 AM
Ronald
+ 2
what is input case 1
8th Sep 2018, 12:20 PM
Ronald
+ 1
Ketan Lalcheta Just understood your problem.. 😂..wait a bit.
2nd Aug 2018, 3:53 PM
Akib
Akib - avatar
+ 1
So.. one thing I think you could do is #1 Check for characters that match #2 make a pointer to that string(char array actually) #3 compare the index numbers of the common characters. This way you will know the actual serial of the matched chars. Hope you understand.
2nd Aug 2018, 3:57 PM
Akib
Akib - avatar
+ 1
Akib Reza #1 we both are doing.. not getting your point #2.. point #3 is what I thought to implement but not getting how to put it in code.. #3 is not that much straight forward... As in first input, KETAN nd TALNE is two different case if input sequence is changed... with KETAN & TALNE , we need to consider E in different sequence for ignorance of same.. (E in first string is found ahead of E in second string and hence to ignore) with TALNE & KETAN , we need to consider E in different sequence for ignorance of same.. (E in first string is found behind of E in second string and hence to ignore)
2nd Aug 2018, 4:04 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 1
I might give it a try and post it in this thread when I have some free time. Gotta sleep for now. 😂 Take some rest.
2nd Aug 2018, 4:47 PM
Akib
Akib - avatar
+ 1
Ketan Lalcheta I managed to create the first stage I told you about. Feeling very sleepy.. Hope you understand now. Will finish the code tomorrow. Coded in C because why not..its easier to write..😂 Edit: finished the code. Check it out. https://code.sololearn.com/c9kyV8f2U4sv/?ref=app
2nd Aug 2018, 5:14 PM
Akib
Akib - avatar
+ 1
Akib Reza appreciate your effort on this dude... Pleasure to have your response and piece of code on this... I checked and it's not upto the mark... Algorithm we are using for this solution is not perfect that is what I am repeatedly saying and hence proved.. we are coding based on cases and that's what make me feel sad.. try giving input as KETAN TALNE , output is 3 which is expected... Just forget about other case.. reverse input and output should be same as 3...but with TALNE KETAN as input, output of code is 1 instead of 3....
2nd Aug 2018, 7:12 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 1
and this one is yet simple test case... More complexity would arise when one of the string has repeat character... for example, NAN & NS (similar to input 2 in my problem statement) we need to consider count of characters in both string while comparing to check common character in both string...
2nd Aug 2018, 7:17 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 1
Ketan Lalcheta I have a great idea. Make an assignment and send it to SL. Let's see how many can solve it in the challenge..😂😂😂😂. Why should we lose our mind.
3rd Aug 2018, 11:05 AM
Akib
Akib - avatar
+ 1
thank you. I will try to overcome from this problem.
7th Sep 2018, 3:43 PM
Ronald
+ 1
pettemsrikanthvarma read this question description ...it's there
8th Sep 2018, 2:51 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
Can you come up with better output? The examples you gave seems pretty vague. You want number of common characters or words?
2nd Aug 2018, 3:33 PM
Akib
Akib - avatar
0
Akib Reza # of characters in string.. Both string are of same length and cannot have space in either string
2nd Aug 2018, 3:35 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
Akib Reza thanks for this.., but it want work for first input.. it might give 4 as output, but expected is 3 whatever you suggested is already there in my sample code...
2nd Aug 2018, 3:49 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
Akib Reza & all, input 1 and 3 is critical... One is having proper order and other is having duplicate character inequality in both strings...
2nd Aug 2018, 3:53 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
char str1[20]; char *ptr = str1; *(ptr+i) (Save the values of i) //use loops with it...just showing syntax I talked about.
2nd Aug 2018, 3:59 PM
Akib
Akib - avatar