+ 1

Code Coach Challenge : How far? in c language

I wrote the code but I I'm getting error for test case #3 and #4. Here is the problem: You are walking from your house to a pond that is down your street. How many blocks over will you have to walk until you get to the pond? Task: Evaluate how many blocks you will have to walk if you are given a representation of your street where H represents your house, P represents the pond, and every B represents a block in between the two. Input Format: A string of letters representing your house, the pond, and blocks on your street. Output Format: An integer value that represents the number of blocks between your house and the pond. Sample Input: BBHBBBBPBBB Sample Output: 4 Here is my code: https://code.sololearn.com/c0eX3e0h9FBW/#c

17th Oct 2021, 11:53 AM
Madalina Peter
Madalina Peter - avatar
5 Answers
+ 3
Tip: Don't count each single B Get only the index of H and P Subtract them. So you can get the number of block between them. To both sides! Maybe you will need abs(difference).
17th Oct 2021, 12:23 PM
Coding Cat
Coding Cat - avatar
+ 3
I've solved it but in another way :D Thank you very much for your help!
17th Oct 2021, 12:40 PM
Madalina Peter
Madalina Peter - avatar
+ 2
I've added this on the code but I forgot to modify here too. But I'm still getting error.
17th Oct 2021, 12:11 PM
Madalina Peter
Madalina Peter - avatar
+ 2
Ok, now you are only searching to the right. What will be happen, if the pod is on the left side?
17th Oct 2021, 12:14 PM
Coding Cat
Coding Cat - avatar
+ 1
Where are you using the "P" in your code. That's your target. So you have to take it into account.
17th Oct 2021, 12:09 PM
Coding Cat
Coding Cat - avatar