+ 1

Very interesting question, why the function returns false if I join all strings into one word?

https://code.sololearn.com/cHkwFTcInDYc/?ref=app Problem is in else if statement. How to repair it?

27th Dec 2022, 4:08 AM
TeaserCode
3 Respuestas
0
It looks like the problem is with the else if statement that is nested inside the inner loop. The else if statement is checking if the first letter of arr2[i] is equal to the last letter of arr2[i1]. If this is true, it is swapping arr2[i] and arr2[i1] and concatenating them. However, this doesn't make sense in the context of the task, which is to join strings whose last letter is the same as the first letter of the next string. To fix this issue, you can remove the else if statement and the swap function call inside it. Instead, you can simply concatenate arr2[i] and arr2[i1] inside the if statement. This way, you will be concatenating strings whose last letter is the same as the first letter of the next string, which is what the task requires. Here is the modified inner loop with the else if statement removed: for(int i1=0; i1<d; i1++) { if(arr2[i][arr2[i].length()-1]==arr2[i1][0]) { yes[i1]=1; arr2[i] += arr2[i1]; result1 = arr2[i]; cout<<arr2[i]<<" "<<arr2[i1]<< endl<<" 1: result1: "<<result1<<endl; } result = result1; } I hope this helps! Let me know if you have any more questions.
27th Dec 2022, 1:24 PM
ENVILO Studios
ENVILO Studios - avatar
0
For this string example, funcion has to return true, it means that it is possible to concatenate all strings. Some strings have the same letter on the first or laste place. So for some strings we have to use swap funcion to satisfy this condition. I do not know how to determine else if to be true. The pupose of this problem is to return true or false (if it is not possible to get one word). So to return true the boolean array has to be true.
27th Dec 2022, 2:17 PM
TeaserCode
0
Does nobody know how to fix it?
28th Dec 2022, 5:35 PM
TeaserCode