第3章 栈和队列
3.1 栈
综合应用题 第3题
#include <stdio.h>
#include <stdlib.h> //malloc所在头文件
#include <iostream>
using namespace std;
int main() {
//SqStack S;
// InitStack(S);
int n=0;
cout<<"输入要检测的序列个数:"<<endl;
cin>>n;
while(n){
string s;
cout<<"请输入序列:"<<endl;
cin>>s;
int cnt=0;
for(int i=0;i<s.length();i++)
{
if(s[i]=='I')
cnt++;
else
cnt--;
if(cnt<0)
break;
}
if(cnt!=0)
{
cout<<"输入序列非法!"<<endl;
}
else
cout<<"输入序列合法!"<<endl;
n--;
}
}