this is my code for this problem:
#include<iostream>
#include<string.h>
using namespace std;
int len;
char s[10000],out[1000];
int xuat(int a)
{
int t1=0,t2=0,i;
if ((s[a]!='(')and (s[a]!=')'))
{
if ( (s[a]!='+') and (s[a]!='-') and (s[a]!='*') and (s[a]!='/') and (s[a]!='^' )) {out[a]=s[a];}
else
{ if (s[a+2]==')') {out[a+2]=s[a];}
else {
for (i=a+1;i<=len;i++)
{
if (s[i]=='(') {t1=t1+1;} else
{ if(s[i]==')')
{ t2=t2+1;}
}
if (t1==t2) {out[i+1]=s[a];return 0;}
}
}
}
}
return 0;
}
int main()
{
int n,i,j,v;
cin>>n;
for (i=1;i<=n;i++)
{ cin>>s;
len=strlen(s);
for (v=0;v<=2*len;v++) {out[v]='0';}
for (j=0;j<=len;j++) // xet tung phan tu cua chuoi
{
xuat(j); // ham xet phan tu vi tri j
}
for (v=0;v<=(2*len);v++) { if (out[v]!='0') {cout<<out[v];}}
cout<<endl;
}
return 0;
}
i check all Example problem, all its are correct
but after submit , error: wrong answer. please held me.