Flowing words Code Coach (Solved) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Flowing words Code Coach (Solved)

Hello. Can you help me with an idea of what could be wrong? The code works only for 4 of the 6 test cases. Problem: If a sentence flows, the first letter of each word will be the same to the last letter of the previous word. Task: Write a program that takes in a string that contains a sentence, checks if the first letter of each word is the same as the last letter of the previous word. If the condition is met, output true, if not, output false. Casing does not matter. Input Format: A string containing a sentence of words. Output Format: A string: true or false. Sample Input: this string gets stuck Sample Output: true Here is the code I wrote: https://code.sololearn.com/cF2WS1YK4u26

21st Oct 2021, 1:59 PM
Madalina Peter
Madalina Peter - avatar
7 Answers
+ 2
Maybe the failing test cases contain no space at all just one word or something. Try to initialise check=1 while declaring. I'm not sure if this is the problem just try it out.
21st Oct 2021, 2:19 PM
Arun Ruban SJ
Arun Ruban SJ - avatar
+ 1
It doesn't work. But thank you for your help anyway.
21st Oct 2021, 2:25 PM
Madalina Peter
Madalina Peter - avatar
+ 1
Madalina Peter, in the task description is mentioned that each word in the sentence should flow with the next one. So in the else clause after check = 1 add break statement. Otherwise your code won't give the right output => for example if two words in the middle of the sentence don't flow, but the loop continues and if the last two words fulfill the condition, the output will be "true", which is obviously wrong. Hope this explanation helps you.
21st Oct 2021, 3:34 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 1
It worked now. Thank you very much for your help!
21st Oct 2021, 5:05 PM
Madalina Peter
Madalina Peter - avatar
0
What does the error showing?? Wrong answer or time limit exceeded or segmentation fault or something else??
21st Oct 2021, 2:33 PM
Arun Ruban SJ
Arun Ruban SJ - avatar
0
Unfortunately, I cannot see the problem because the test cases that are failing are hidden.
21st Oct 2021, 2:36 PM
Madalina Peter
Madalina Peter - avatar
0
Ok if it is a time limit exceeded problem, adding a break statement in the else block will solve it
21st Oct 2021, 2:40 PM
Arun Ruban SJ
Arun Ruban SJ - avatar