标记数组的做法,哪里有问题
查看原帖
标记数组的做法,哪里有问题
742157
ZYK_luogu楼主2023/4/30 18:44
#include <iostream>
#include <cstring>
using namespace std;
#deine maxn 105

char get(char c) {
	switch(c) {
		case '(':
			return ')';
		case ')':
			return '(';
		case '[':
			return ']';
		case ']':
			return '[';
	}
}

int main() {
	string str;
	cin >> str;
	int point[maxn], len = str.length();
	memset(point, 0, sizeof(point));
	for(int i = 1; i < len; i ++) 
		if(str[i - 1] == get(str[i]))
			point[i] = point[i - 1] = 1;
	for(int i = 0; i < len; i ++)
		if(point[i])
			cout << str[i], i ++;
		else
			if(str[i] == '(' || str[i] == '[')
				cout << str[i] << get(str[i]);
			else
				cout << get(str[i]) << str[i];
	return 0;
}

2023/4/30 18:44
加载中...