help me plz
Code: Select all
#include <iostream>
#include <stack>
using namespace std;
int main()
{
int num;
char tmpChar[6];
int tmpPos, tmp;
int bracketCount;
int sum;
bool flg, bracketFlag;
stack<int> st;
while(cin >> num)
{
bracketCount=0;
sum=0;
tmpPos=0;
flg=false;
bracketFlag=false;
do {
cin >> tmpChar[tmpPos];
if (tmpChar[tmpPos]=='(')
{
tmpChar[tmpPos]=0;
++bracketCount;
if (tmpPos)
{
tmp=atoi(tmpChar);
st.push(tmp);
sum+=tmp;
}
st.push(0); // insert bracket
tmpPos=0;
}
else if (tmpChar[tmpPos]==')')
{
tmpChar[tmpPos]=0;
--bracketCount;
if (tmp=st.top())
{
while(tmp)
{
sum-=tmp;
st.pop();
tmp=st.top();
}
bracketFlag=false;
}
else
{
if (bracketFlag)
{
flg=flg | (sum==num);
bracketFlag=false;
}
bracketFlag=true;
}
st.pop(); // delete bracket
}
else
++tmpPos;
} while(bracketCount);
if (flg)
cout << "yes" << endl;
else
cout << "no" << endl;
}
return 0;
}