zoukankan      html  css  js  c++  java
  • 洛谷P3719 REXP 题解

    题目

    一道考验递归的题目,在面对这种字符串处理的题时,还是应该用递归这种比较好看懂而且比较简单写的算法。

    (code)

    // luogu-judger-enable-o2
    #include <cstring>
    #include <algorithm>
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #define int long long
    using namespace std;
    int digui(int ans)
    {
        char c;
        while (cin >> c)
        {
            if (c == ')') return ans;
            if (c == 'a') ans++;
            if (c == '(') ans += digui(0);
            if (c == '|') return ans = max(ans, digui(0));//因为最外圈可能没有括号,所以必须return 
        }
        return ans;
    }
    signed main()
    {
        printf("%lld", digui(0));
    }
  • 相关阅读:
    宏任务、微任务
    类和模块
    每日日报
    每日日报
    每日日报
    每日日报
    每日日报
    每日日报
    每日日报
    每日日报
  • 原文地址:https://www.cnblogs.com/liuwenyao/p/10547052.html
Copyright © 2011-2022 走看看