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
10/21/2021 1:59:16 PMMadalina Peter
7 AnswersNew Answer
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.
It doesn't work. But thank you for your help anyway.
It worked now. Thank you very much for your help!
What does the error showing?? Wrong answer or time limit exceeded or segmentation fault or something else??
Unfortunately, I cannot see the problem because the test cases that are failing are hidden.
Ok if it is a time limit exceeded problem, adding a break statement in the else block will solve it
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.