萌新求教
查看原帖
萌新求教
700716
Little_Brown_Rabbit楼主2023/10/29 14:10

-```c #include<bits/stdc++.h>

using namespace std;

inline bool match(char c1,char c2)

{

return (c1=='(' && c2==')' ) || (c1=='[' && c2==']') ;

}

bool judge(const string& s)

{

stack<char> st;

for(char c:s)

{

	if(c=='(' || c=='[') st.push(c);
    
	else
    
	{
    
		if(!(c==')'|| c==']')) continue;
        
		if(st.empty()|| 
        !match(st.top(),c)) return false;
        
		st.pop(); 
        
	}
    
}

}

int main()

{

int n;

string s;

getline(cin,s),n=stoi(s);

while(n--)

{

	getline(cin,s);
    
	puts(judge(s) ? "Yes":"No");
    
	
}

return 0;

}

萌新求教,为什么每一次输出都是
terminate called after throwing an instance of 'std::invalid_argument'
  what():  stoi
2023/10/29 14:10
加载中...