题目链接
样例输入
2
aacbcbcc
aa
样例输出
Pattern 1: More aliens!
Pattern 2: Still Looking.
题解:判断a,b,是否匹配,c随意位置
#include<bits/stdc++.h>
using namespace std;
#define ll long long
string s;
stack<char>q;
int ds()
{
for(int i=0;i<s.length();i++)
{
if(s[i]=='a')
q.push('a');
else if(s[i]=='b')
{
if(q.empty())
return 0;
else q.pop();
}
else if(s[i]!='c')
return 0;
}
return q.empty();
}
int main()
{
ios::sync_with_stdio(false);
int n;
cin>>n;
for(int tip=1;tip<=n;tip++)
{
cin>>s;
while(!q.empty())
q.pop();
if(ds())
cout<<"Pattern "<<tip<<": More aliens!"<<endl;
else
cout<<"Pattern "<<tip<<": Still Looking."<<endl;
if(tip!=n)
cout<<endl;
}
return 0;
}