萌新求调
查看原帖
萌新求调
646208
Hughpig楼主2025/1/17 12:10

目前只写了 Match Error 和 Unclosed Mark,但第八个点的 Unclosed Mark 检测不出,求调

#include<bits/stdc++.h>
using namespace std;

constexpr int N=1e6+7;

int n;
string text[N];

stack<string> stk;

bool check_match(){
	bool flag=1,is_quote=0;
	string tmp;
	for(int i=1;i<=n;++i){
		for(auto c:text[i]){
			if(c=='['){
				tmp="";
				flag=1;
				continue;
			}
			if(c==']'){
				//cout<<tmp<<' ';
				if(is_quote==1){
					if(tmp=="/quote"){
						is_quote=0;
						stk.pop();
					}
					flag=0;
					tmp="";
					continue;
				}
				if(tmp[0]=='/'){
					if(tmp=="/quote"&&is_quote==1)is_quote=0;
					if(stk.size()==0)return 0;
					string qwq=stk.top();
					stk.pop();
					qwq="/"+qwq;
					//cout<<qwq<<' '<<tmp<<'\n';
					if(qwq.substr(0,tmp.size())!=tmp)return 0;
				}
				else stk.push(tmp);
				if(tmp=="quote")is_quote=1;
				flag=0;
				//cout<<tmp<<' ';
				tmp="";
			}
			if(flag){
				tmp+=c;
			}
		}
	}
	//cout<<"qwq\n";
	return 1;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	while(getline(cin,text[++n]));
	--n;
	if(!check_match())cout<<"Match Error",exit(0);
	if(stk.size())cout<<"Unclosed Mark",exit(0);
}
2025/1/17 12:10
加载中...