+ 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...
27 Antworten
+ 2
submitted... I am not sure whether this will get approved or not..
+ 2
https://code.sololearn.com/c35rM92Bnk7Q/?ref=app
ok but in this one problem that strlen is not working.
+ 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
+ 2
https://code.sololearn.com/c35rM92Bnk7Q/?ref=app
once check it I hope this code will reach your expectations.
thank you.
+ 2
what is input case 1
+ 1
Ketan Lalcheta Just understood your problem.. 😂..wait a bit.
+ 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.
+ 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)
+ 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.
+ 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
+ 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....
+ 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...
+ 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.
+ 1
thank you.
I will try to overcome from this problem.
+ 1
pettemsrikanthvarma read this question description ...it's there
0
Can you come up with better output? The examples you gave seems pretty vague.
You want number of common characters or words?
0
Akib Reza # of characters in string.. Both string are of same length and cannot have space in either string
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...
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...
0
char str1[20];
char *ptr = str1;
*(ptr+i)
(Save the values of i)
//use loops with it...just showing syntax I talked about.