7-4 堆栈操作合法性 (10分)

手速要快

#include<iostream>
using namespace std;
int a[100010];
int main()
{
    int n,m;
    string s;
    cin >> n >> m;
    while(n--){
        bool flag = true;
        int t=0;
        cin >> s;
        for(int i=0;i<s.size();i++){
            if(s[i]=='S') ++t;
            else --t;
            if(t<0||t>m) {
                flag=false;
                break;
            }
        }
        if(t==0&&flag) cout << "YES" << endl;
        else cout << "NO" <<endl;
    }
    return 0;
}

发布了10 篇原创文章 · 获赞 0 · 访问量 99

猜你喜欢

转载自blog.csdn.net/m0_46383408/article/details/104894400