+ 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
6 odpowiedzi
+ 1
Niirmaal Twaatii I changed it now
+ 1
I got it. I just didnt think about H and P coming before or after each other
0
i can't see the contents as it's premium :V
why don't you post the question & code
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;
}
0
zack lol i came up with this
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.