Whad did i do wrong it fails somo of my tests | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Whad did i do wrong it fails somo of my tests

How Far? 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 https://code.sololearn.com/c5OSBo229jrV/?ref=app

4th Sep 2022, 1:44 PM
Costy Game
Costy Game - avatar
3 Answers
+ 2
https://code.sololearn.com/cJDx4mY4SBnD int H,P; for(size_t i=0; i<map.size(); i++) if(map[i]=='H') H=i; else if(map[i]=='P') P=i; cout << abs(P-H)-1;
4th Sep 2022, 2:11 PM
SoloProg
SoloProg - avatar
+ 2
Thanks
5th Sep 2022, 6:18 PM
Emmanuel Oluwasanya
Emmanuel Oluwasanya - avatar
0
tricky logic you need to analize is the pond may be left to house also.. Ex: BBPBBBHBB your code failing this
4th Sep 2022, 2:08 PM
Jayakrishna 🇮🇳