24分,求教!!!
查看原帖
24分,求教!!!
945734
wangyvning楼主2024/8/1 17:34
#include<bits/stdc++.h>
using namespace std;
const int maxn=51000;
struct node{
	int id;
	char v;
}; 
char s[maxn];
stack<node>sta;
char a[maxn];
int main(){
	scanf("%s",s+1);
	int n=strlen(s+1);
	for(int i=1;i<=n;i++){ 
		if(s[i]=='('){
			sta.push(node{i,s[i]});
			a[i]=')';
		}else if(s[i]=='['){
			sta.push(node{i,s[i]});
			a[i]=']';
		}else if(s[i]==')'){
			if(!sta.empty()&&sta.top().v=='('){
				a[i]='@';
				a[sta.top().id]='@';
				sta.pop();
			}else{
				a[i]='[';
			} 
		}
	}
	for(int i=1;i<=n;i++){
		if(a[i]=='('||a[i]=='['){
			printf("%c%c",s[i],a[i]);
		}else if(a[i]==')'||a[i]==']'){
			printf("%c%c",s[i],a[i]);
		}else{
			printf("%c",s[i]);
		}
	}
	return 0; 
} 

这就是24分代码,哪位大佬能够帮忙一下?

2024/8/1 17:34
加载中...