Query Regarding Spreading charges problem from starters 77

#include <bits/stdc++.h>
using namespace std;

int f(string str, int n){
    stack<char> s;
    int count = 0;
    int i = 1;
    s.push(str[0]);
    while (true){
        if (i == n) break;
        if (str[i] == s.top()) s.push(str[i++]);
        else if (str[i] != s.top()){
            if (s.top() == '0'){
                while (!s.empty() && s.top() == '0') s.pop();
                if (!s.empty() && s.top() != str[i]){
                    s.push('0');
                    s.push(str[i++]);
                }
                else s.push(str[i++]);
            }
            else if (s.top() == '+' && str[i] == '0'){
                while (i < n && str[i] == '0') i++;
                if (i == n) continue;
                if (s.top() != str[i]){
                    s.push('0');
                    s.push(str[i++]);
                }
                else s.push(str[i++]);
            }
            else if (s.top() == '-' && str[i] == '0'){
                while (i < n && str[i] == '0') i++;
                if (i == n) continue;
                if (s.top() != str[i]){
                    s.push('0');
                    s.push(str[i++]);
                }
                else s.push(str[i++]);
            }
            else {
                if (i == n) continue;
                s.push(str[i++]);
            }
        }
    }
    while (!s.empty()){
        if (s.top() == '0') count++;
        s.pop();
    }
    return count;
}

int main() {
	// your code goes here
	int t;
    cin >> t;
    while (t--){
        int n;
        cin >> n;
        string s;
        cin >> s;
        cout << f(s, n) << endl;
    }
	return 0;
}

Can anyone help me figure out testcases on which above code fails.

Try the initial strings “+00-” and “-00+”.

Are these 2 inputs supposed to give 2 as an output?

No, they should both give zero.