I was coding questions in hackerearth and i got stuck in [Winning side problem][1]
[1]: Winning side | Practice Problems
I have written code as follow and not able to know where i am going wrong my code doesn’t display any output:-
#include
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];
v=a[i];
char s[v];
long num[v];
cin >> s[v];
for(j=0;j> num[j];
if(s[j]=='g')
{
g += num[j];
}
else if(s[j]=='b')
{
b += num[j];
}
}
if(g>b)
{
cout << "g"<<" "<g)
{
cout << "b" <<" " << b-g;
}
}
return 0;
}
1 Like
thedark
2
You are not taking the input string correctly. This is the corrected version Ubuntu Pastebin
1 Like
eager
3
There were three errors in your code:
- 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.
- The string input was not correct. I would recommend you to go through strings in c++ for help.
- You were not printing the result of a test case in new line.
The corrected code can be found here
3 Likes