Why runtime error?

I am solving a problem at UVa Online judge 112 - Tree Summing problem (https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=48)

I've written the following code for this. But I got RUNTIME_ERROR.

Why this? Where is the fault?

#include <iostream>
#include <stack>

using namespace std;

bool Isleef(stack<int> tree,int deep);
int Summing(stack<int> tree);

int main(void)
{
int find = 0;
int tmp = 0;
stack<int> tree;
char c;
int open, close;

open = close = 0;
bool Isfind = false;
bool Ispositive = true;

while (cin >> find)
{
while (c = getchar())
{
if (c == '(')
{
open++;
if (!Ispositive)
Ispositive = true;
if (tmp != 0)
{
tree.push(tmp);
tmp = 0;
}
}
else if (c == ')')
{
close++;
if ((open - close) == 0)
{
break;
}
if (Isleef(tree, open - close) )
{
if (find == Summing(tree))
{
Isfind = true;
}
}
else
{
tree.pop();
}
}
else if (c == '-')
{
Ispositive = false;
}
else if (c >= '0' && c <= '9')
{
if (Ispositive)
tmp = tmp * 10 + (c - '0');
else
tmp = tmp * 10 - (c - '0');
}
else if (c == EOF)
break;
}


if (Isfind)
cout << "yes" << endl;
else
cout << "no" << endl;


if (c == EOF)
break;

find = 0;
tmp = 0;
open = 0;
close = 0;
Isfind = false;
Ispositive = true;

while (!tree.empty())
tree.pop();
}

return 0;
}

bool Isleef(stack<int> tree, int deep)
{
int i;
for (i = 0; i < deep; i++)
tree.pop();

if (tree.empty())
return true;
else
return false;
}

int Summing(stack<int> tree)
{
int sum = 0;

while (!tree.empty())
{
sum += tree.top();
tree.pop();
}

return sum;
}
What input?
By instance
0 (0 () ())


Also
1 (1 () (2 () ()) )
your program wrongfully outputs yes
Topic archived. No new replies allowed.