1 条题解

  • 0
    @ 2026-5-19 22:38:06

    #include

    #include

    using namespace std;

    int t;

    stack s;

    int main(){

    cin>>t;
    
    while(t--){
    
    	string c;
    
    	cin>>c;
    
    	int f=0;
    
    	for(int i=0;i<c.size();i++){
    
    		if(c[i]=='('||c[i]=='['||c[i]=='{'){
      
    			s.push(c[i]);
        
    		}else{
      
    			if(s.empty()){
        
    				f=1;
          
    				break;
          
    			}else 
        if(c[i]==')'&&s.top()!='('||c[i]==']'&&s.top()!='['||c[i]=='}'&&s.top()!='{'){
        
    				f=1;
          
    				break;
          
    			}else{
        
    				s.pop();
          
    			}
        
    		}
      
    	}
    
    	if(f)cout<<"NO"<<endl;
    
    	else cout<<"YES"<<endl;
    
    }
    
    return 0;
    

    }

    • 1

    信息

    ID
    3553
    时间
    1000ms
    内存
    256MiB
    难度
    8
    标签
    (无)
    递交数
    20
    已通过
    7
    上传者