Hackerearth winning side question

I was coding questions in hackerearth and i got stuck in [Winning side problem][1]
[1]: https://www.hackerearth.com/practice/basic-programming/implementation/basics-of-implementation/practice-problems/algorithm/winning-side/

I have written code as follow and not able to know where i am going wrong my code doesn’t display any output:-

using namespace std;

int main() {
    long t,g=0,b=0;
    cin >> t;
    long a[t];
    long i,j,v;
    for(i=0;i> a[i];
        char s[v];
        long num[v];
        cin >> s[v];
        for(j=0;j> num[j];
                g += num[j];
            else if(s[j]=='b')
                b += num[j];
            cout << "g"<<" "<g)
            cout << "b" <<" " << b-g; 
    return 0;

1 Like

You are not taking the input string correctly. This is the corrected version http://paste.ubuntu.com/23195770/

1 Like

There were three errors in your code:

  1. Each time you enter a test case you should initialize b and g to 0 which you missed so the values of previous test cases accumulated.
  2. The string input was not correct. I would recommend you to go through strings in c++ for help.
  3. You were not printing the result of a test case in new line.

The corrected code can be found here