string sort
i am trying to first sort normally and then comparing for substring
Whats wrong in my code?
Hello @sktg99,
-
The size of array is 100 but there can be at max 1000 strings possible as per question.
Solution:
int n;
cin >> n;
string s[n]; -
You have to print the each string in a separate line.
Solution:
for (int i = 0; i < n; i++) {
cout << s[i]<<endl; -
The logic for substring is wrong.
Print the value of a and b, it would never work.
Solution:
Run the loop inside the function q=min(l1,l2)
I have modified your code.
Now it is passing the test cases:
https://ide.codingblocks.com/s/134114
Hope, this would help.
Give a like, if you are satisfied.
what have u changed in point 3? i didn’t get
You were iterating for i=0 to l1 for each case.
I made it run for q=min(l1,l2) i.e for the length of the string from a and b which is smaller.
Reason:
For the case, when b is the sub-string of a:
a= batman
b= bat
Your code was returning 0
After modification, it is returning 0.
If you still have doubt, let me know.
ok thanks for solving all my doubts
Anytime.
Now, mark this as resolved too.