1 条题解

  • 0
    @ 2025-7-11 20:40:43

    O(n)O(n) 模拟

    用一个bool变量表示当前为登录还是非登录状态。 分类讨论每次操作并且维护登录状态,只有在private并且非登录状态时才会令答案加一

    #include<bits/stdc++.h>
    
    using namespace std;
    
    typedef long long LL;
    typedef pair<LL, LL> PII;
    
    #define x first
    #define y second
    
    const int N = 5e3 + 10, mod = 1e9 + 7;
    
    int main()
    {
        int n;
        cin >> n;
        bool login = 0;
        int ans = 0;
        while(n --)
        {
            string s;
            cin >> s;
            if(s == "login") login = 1;
            else if(s == "logout") login = 0;
            else if(s == "private")
            {
                if(!login)
                    ans ++;
            }
        }
        cout << ans << endl;
    }
    
    • 1

    信息

    ID
    152
    时间
    1000ms
    内存
    256MiB
    难度
    2
    标签
    递交数
    13
    已通过
    11
    上传者