学生物的还不赶紧转码工,想什么呢# Biology - 生物学
s*n
1 楼
Implement a function string balanceParanthesis(string s); which given a
string s consisting of some parenthesis returns a string s1 in which
parenthesis are balanced and differences between s and s1 are minimum.
Eg - "(ab(xy)u)2)" -> "(ab(xy)u)2"
")))(((" -> ""
Is my idea correct:?
void eliminate (int left[], int right[],leftsize, rightsize)//in left right
there are position info. left[0] is the position of first left paranthesis
{
sort (left, left+leftsize);
sort (right, right+rightsize);
int leftcurrent=0, rightcurrent;
for (int rightcurrent=0; rightcurrent if (leftcurrent>=leftsize) {for (int j=rightcurrent;j right[j]=-1; break;}
if (left[leftcurrent] leftcurrent++;
}
else right[rightcurrent]=-1; //remove it
}
for (int j=leftcurrent; j }
string s consisting of some parenthesis returns a string s1 in which
parenthesis are balanced and differences between s and s1 are minimum.
Eg - "(ab(xy)u)2)" -> "(ab(xy)u)2"
")))(((" -> ""
Is my idea correct:?
void eliminate (int left[], int right[],leftsize, rightsize)//in left right
there are position info. left[0] is the position of first left paranthesis
{
sort (left, left+leftsize);
sort (right, right+rightsize);
int leftcurrent=0, rightcurrent;
for (int rightcurrent=0; rightcurrent
if (left[leftcurrent]
}
else right[rightcurrent]=-1; //remove it
}
for (int j=leftcurrent; j