C. Move Brackets

    技术2026-02-01  6

    #include<iostream> #include<cstring> using namespace std; int main(){ int t; cin>>t; for(int i=0;i<t;i++){ int n; cin>>n; char str[n+1]; cin>>str; char stack[n+1]; int j = 0,k = -1; while(str[j]!='\0'){ if(str[j]=='('){ k++; stack[k] = '('; }else{ if(stack[k]=='('){ stack[k] = ' '; k--; }else{ k++; stack[k] = ')'; } } j++; } cout<<(k+1)/2<<endl; } }
    Processed: 0.028, SQL: 12