2 solutions

  • 1
    @ 2024-8-21 11:10:56
    #include <bits/stdc++.h>
    using namespace std;
    const int N=300;
    char a[N];
    stack<int>k;
    int main()
    {
    	bool fx=true;
    	int i;
    	int s_1=0,b_1=0,s_2=0,b_2=0; 
    	cin>>a;
    	i=strlen(a);
    	for(int j=0;j<i;j++)
    	{
    		
    		if(a[j]=='[')
    		{
    			s_2++;
    			k.push(1);
    			fx=true;
    			continue;
    		}
    		if(a[j]==']')
    		{
    			b_2++;
    			if(b_2>s_2)
    			{
    				fx=true;
    				break;
    			}
    			if(k.top()==1)
    			{
    				fx=false;
    				k.pop();
    			} 
    			else break;
    			if(s_2==b_2)fx=false;
    			continue;
    		}
    		if(a[j]=='(')
    		{
    			s_1++;
    			k.push(2);
    			continue;
    		}
    		if(a[j]==')')
    		{
    			b_1++;
    			if(b_1>s_1)
    			{
    				fx=true;
    				break; 
    			} 
    			if(k.top()==2)
    			{
    				fx=false;
    				k.pop();
    			} 
    			else break;
    			if(s_1==b_1)fx=false;
    			continue;
    		}	
    	}
    	if(s_2>b_2 || s_1>b_1)
    	{
    		fx=true;
    	}
    	if(fx==true)cout<<"Wrong";
    	if(fx==false) cout<<"OK"; 
    	return 0;
    }
    

    Information

    ID
    967
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    3
    Tags
    (None)
    # Submissions
    65
    Accepted
    13
    Uploaded By