栈
一、题目要求
输入由A~H打乱顺序的序列,判断是否为FILO序列
例如:
输入:ACBEFDGH 输出:1
输入:ADHCGBEF 输出:0
二、代码如下
#include<iostream>
using namespace std;
char a[8];
char x,p='A';
int top=0,count=0;
int main(){
scanf("%c",&x);
while(count<8){//不能为for循环,每个字母必须符合FILO才可以
if(top>0&&a[top-1]==x){//注意判断条件
top--;scanf("%c",&x);
count++;
}
else if(p<='H'){
a[top++]=p++;
}
else{
printf("0");return 0;
}
}
printf("1");return 0;
}