#include <iostream>
using namespace std;
void judge(string s)
{
int cntI = 0, cntO = 0;
for (int i = 0; s[i] != '\0'; i ++)
{
if (s[i] == 'I')
cntI ++;
else
{
cntO ++;
if (cntO > cntI)
{
cout << "FALSE" << endl;
return ;
}
}
}
if (cntI == cntO) // 由于最后必须为空,因此两者最终数量必定相同
{
cout << "TRUE" << endl;
return ;
}
else
{
cout << "FALSE" << endl;
return ;
}
}
int main()
{
string s;
while (cin >> s && s[0] != '0')
judge(s);
return 0;
}
BJFU 245基于栈的可操作判断(未用到栈)
最新推荐文章于 2023-03-16 15:03:23 发布