怎么卡48了求帮助
查看原帖
怎么卡48了求帮助
1128530
PrincedeChine楼主2024/10/2 10:19
#include<iostream>
#include<cstring>

using namespace std;

void Complete(const string &s){
    int a;
    int i;
    a = s.length();
    for(i = a - 1; i >= 0; i--){
        if(s[i] == ')'){
            if(i > 0 && s[i-1] == '('){
                cout << "()";
                i--;
            }
            else{
                cout << "()";
            }
        }
        if(s[i] == ']'){
            if(i > 0 && s[i-1] == '['){
                cout << "[]" ;
                i--;
            }
            else{
                cout << "[]" ;
            }
        }
        if(s[i]=='('){
        	cout<<"()";
		}
		if(s[i]=='['){
			cout<<"[]";
		}
    }
    
}

int main(){
    string s;
    cin >> s;
    Complete(s);
    return 0;
}
2024/10/2 10:19
加载中...