Could i get some help on why this is failing? It only fails test 3 and 4 but they are hidden so i cant look at them. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Could i get some help on why this is failing? It only fails test 3 and 4 but they are hidden so i cant look at them.

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/c4wsRpz2M80e/?ref=app

21st Mar 2022, 12:23 AM
zack
6 Answers
+ 1
Niirmaal Twaatii I changed it now
21st Mar 2022, 12:28 AM
zack
+ 1
I got it. I just didnt think about H and P coming before or after each other
21st Mar 2022, 12:42 AM
zack
0
i can't see the contents as it's premium :V why don't you post the question & code
21st Mar 2022, 12:24 AM
Twaatii
Twaatii - avatar
0
zack #include <iostream> using namespace std; int bCount(string map) { int blocks = 0; int houseIndx = map.find('H'); int pondIndx = map.find('P'); if(pondIndx < houseIndx ){ for(int i = pondIndx+1 ; i <= houseIndx-1 ; i++) blocks += 1; } if(pondIndx > houseIndx ){ for(int i = houseIndx+1 ; i <= pondIndx-1 ; i++) blocks += 1; } return blocks; } int main() { string map; cin >> map; cout << bCount(map); return 0; }
21st Mar 2022, 12:44 AM
Twaatii
Twaatii - avatar
0
zack lol i came up with this
21st Mar 2022, 12:45 AM
Twaatii
Twaatii - avatar
0
It is pretty scummy of SoloLearn to change the order of H & P in the hidden cases. It would be much nicer if they did it in the visible test cases.
21st Mar 2022, 8:56 AM
HungryTradie
HungryTradie - avatar