Cant pass any test case in blocked website. Please help!

Hi, Iam pavankalyan. I recently tried to solve ‘blocked websites’ problem that appeared in one of the may challenges. It is working fine in my system. I even tried all the test cases that are provided by various users in the forums. My code is giving correct output for all of them. But it is not passing even one test case when i submit it. I can’t understand the problem in my code. Please anyone help me. Thanks in advance. Here is my code to the problem.

I seriously feel that the problem lies somewhere in input rather than the algorithm. Either the practice test cases are not well formatted (eg- missing space b/w +/i and site name etc) or its something else.

If possible, try replacing your getchar() with cin and get back to us!

*You’ve initialized filter and you are checking the beginning character of curfilter

list<struct filter> filters;
bool added_to_filter;
for(vector<string>::iterator blocksite=block.begin(); blocksite!=block.end(); ++blocksite){
    added_to_filter=false;

    for(list<struct filter>::iterator curfilter=filters.begin(); curfilter!=filters.end(); ++curfilter){
        
        if((*blocksite)[0]==(*curfilter).key[0]){.......

I donno how c++ works but should’nt this misbehave?

Thank you Simha for spending time to correct my code and to answer your query, the code above works fine, it does not misbehave. In order to correctly interpret the above code, just try to learn about ‘iterators’ concept in C++ standard library.

Thank you friend for your valuable suggestion. I changed the initial data reading code to

vector block,allow;
string temp;
int n;
char tag;
cin >> n;
for(int i=0;i<n;i++){
cin >> tag;
getline(std::cin,temp,’\n’);
if(temp[0]==’ ‘)
temp.erase(0,1);//if leading whitespaces are present removed it
if(tag==’+’)
allow.push_back(temp);
else if(tag==’-’)
block.push_back(temp);
}

now my code is somewhat better now. it had passed around 10 testcases on submission. but still getting a WA on rest.

Ok, i will run your code for some corner cases and get back to you. I am glad that using cin helped in the problem somewhat :slight_smile:

//