2022/1/20基础数据结构和STL自学习题练习

https://ac.nowcoder.com/acm/contest/19850

A:EZ

B:新手常见眼瞎,每个数据不爆int

没注意总和爆int,查代码查10min,服了

C:暴力枚举

D:sort的应用

E:栈的应用,若某字符串合法,那么对于每个a必有最近的b与之匹配

#include <bits/stdc++.h>
using namespace std;
signed main(int argc, char* argv[])
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    stack<char> stk;
    string s;
    cin >> s;
    int l = s.size();
    for (int i = 0; i < l; ++i)
    {
        char c = s[i];
        if (stk.empty() && c == 'b')
        {
            cout << "Bad" << endl;
            return 0;
        }
        if (c == 'a')
            stk.push(c);
        if (c == 'b')
            stk.pop();
    }
    if (stk.empty())
        cout << "Good" << endl;
    else
        cout << "Bad" << endl;
    return 0;
}

 

posted on 2022-01-20 20:52  QSeveN  阅读(71)  评论(0)    收藏  举报

导航