只对了两个点,到底是哪里错了
查看原帖
只对了两个点,到底是哪里错了
1228836
destiny_w楼主2024/9/26 11:37

#include<bits/stdc++.h> using namespace std; stack s; int main(){ string t; getline(cin,t); int len=t.length();

//cout<<"pusha: "<<t[0]<<endl; for(int i=0;i<len;++i){ if(s.empty() ){ if(t[i]=='(' || t[i]==')'){ s.push(t[i]); //cout<<"pusha: "<<t[i]<<endl; }

		continue;
	}

	char nz=s.top();
	if(t[i]=='(' ){
		s.push(t[i]);
		//cout<<"pushb: "<<t[i]<<endl;
	}
	else if(t[i]==')'){
		if(nz=='('){
			s.pop();
			//cout<<"popa: "<<nz<<endl;
		} 
		else if(nz==')'){
			s.push(t[i]);//cout<<"pushc: "<<t[i]<<endl;
		}
		 
		
	}
	


}
cout<<s.size();

}

_ ~~**
2024/9/26 11:37
加载中...