我来拯救大家,花了一个小时

☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺  •  1年前


include <bits/stdc++.h>

using namespace std;

int main() {

stack<char>s;
stack<int>p;
int i, sum = 0, z;
char a[100000];
cin >> a;
int len = strlen(a);
for (i = 0; i < len; i++) {
	s.push(a[i]);
	z = 0;
	if (p.size() == 0) {
		z = 1;
	}
	if (z == 1 && a[i] == 'O') {
		sum = 1;
		break;
	}
	if (a[i] == 'I') {
		p.push(1);
	}
	if (a[i] == 'O') {
		p.pop();
	}
}
if (sum == 1) {
	cout << "NO";
} else {
	cout << "YES";
}
return 0;

}


评论:

请先登录,才能进行评论