蒟蒻20pts RE求助
查看原帖
蒟蒻20pts RE求助
755314
EllaSun2009楼主2022/10/9 13:21
#include<iostream>
#include<string>
#define int unsigned long long
using namespace std;
const int N = 0x3f3f3f;
int sta[N][2], top;
bool b[N];
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
	string str;
	cin >> str;
	int len = str.size();
	int maxx = 0, l = 0;
	for (int i = 0; i < len; i++){
		if (str[i] == ')' && sta[top][0] == '(') b[i] = b[sta[top][1]] = 1, top--;
		else if (str[i] == ']' && sta[top][0] == '[') b[i] = b[sta[top][1]] = 1, top--;
		else top++, sta[top][0] = str[i], sta[top][1] = i;
	}
	int i = 0;
	while (i < len){
		while (b[i] == 0) i++;
		int j = i;
		while (b[j] == 1) j++;
		if (j - i > maxx) maxx = j - i, l = i;
		i = j;
	}
	for (int i = 0; i < maxx; i++) cout << str[l + i];
	cout << endl;
	return 0;
}

代码已格式化

2022/10/9 13:21
加载中...