Help me in solving ONP problem ... plz the issue in this code

My issue

plz

My code


#include<iostream>
#include<string>
#include<stack>
#define  ll long long int
using namespace std;

int main() {
	// your code goes here
	ll t;
	cin>>t;
   while(t-->0){
       string s;
       cin>>s;
       stack<char>p;
       string ans="";
        
       for(ll i=0;i<s.length();i++){
          
          if(s[i]=='('){
              p.push(s[i]);
          }
          else if(s[i]=='+' ||s[i]=='-'||s[i]=='*'||s[i]=='/'||s[i]=='^'){
              p.push(s[i]);
          }
          else if(isalpha(s[i])){
              ans+=s[i];
          }
          else if(s[i]==')'){
           while(p.top()!='(' && !p.empty()){
              
               ans+=p.top();
               
           }
           if(!p.empty()){
           p.pop();}
       }
       }
      cout<<ans<<endl;
   }
	return 0;
}

Problem Link: ONP Problem - CodeChef

@deepakjdh31
U r not popping the p.top() in while loop
i have corrected it .

#include<iostream>
#include<string>
#include<stack>
#define  ll long long int
using namespace std;

int main() {
	// your code goes here
	ll t;
	cin>>t;
   while(t-->0){
       string s;
       cin>>s;
       stack<char>p;
       string ans="";
        
       for(ll i=0;i<s.length();i++){
          
          if(s[i]=='('){
              p.push(s[i]);
          }
          else if(s[i]=='+' ||s[i]=='-'||s[i]=='*'||s[i]=='/'||s[i]=='^'){
              p.push(s[i]);
          }
          else if(isalpha(s[i])){
              ans+=s[i];
          }
          else if(s[i]==')'){
           while(p.top()!='(' && !p.empty()){
              
               ans+=p.top();
               p.pop();
               
           }
           p.pop();
       }
       }
      cout<<ans<<endl;
   }
	return 0;
}