有谁能救救我

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

int main(){
	string s;
	cin>>s;
	stack<char> fo;
	for(int i = 0; i<=sizeof(s); i++){
		int a = int(s[i]);
		cout<<a<<" ";
		if(a == 41 || a == 93){
			if(a-1 == int(fo.top()) || a-2 == int(fo.top())){
				fo.pop();
			}
		}else{
			fo.push(s[i]);
		}
	}
	if(fo.empty()){
		cout<<"OK";
	}else{
		cout<<"Wrong";
	}
	return 0;
}

在这个代码里,我的a值会变成负数,所以有没有哪位能帮帮我,说明一下(请详细点,谢谢)!

1 个赞

帮你用了
image
以后记得加上这个哦

1 个赞

这一步明显错了
应该为

for(int i = 0; i<s.size(); i++)

希望能有解决方案和赞

1 个赞

但我问的问题莫有解决啊

1 个赞