zoukankan      html  css  js  c++  java
  • 洛谷 P3952 时间复杂度 (C/C++)

    洛谷 P3952 时间复杂度

    #include <iostream>
    #include <cstdio>
    #include <stack>
    #include <set>
    #include <string>
    using namespace std;
    int getNumber(string s) {
      int res = 0;
      for(int i = 0; i < s.length(); i++) {
        res *= 10;
        res += s[i] - '0';
      }
      return res;
    }
    int getO(string s) {
      int res = 0;
      if(s[2] == '1') return 0;
      for(int i = 4; s[i] != ')'; i++) {
        res *= 10;
        res += s[i] - '0';
      }
      return res;
    }
    int main() {
      int t; cin >> t;
      stack<int> cache;
      for(int i = 0; i < t; i++) {
        int l; string o;
        scanf("%d", &l); cin >> o;
        stack<string>name;
        set<string>check_name;
        int finallyO = 0, tempO = 0;
        bool flag = true, alone = false;
        int EFs = 0;
        for(int j = 0; j < l; j++) {
          char ch; getchar();
          scanf("%c", &ch);
          if(ch == 'E') {
            EFs -= 1; tempO -= 1;
            if(!name.empty()) {
              check_name.erase(name.top()); name.pop();
            }
            if(!EFs) {
              alone = false;
              tempO = 0;
            }
          } else if(ch == 'F') {
            EFs += 1;
            string v, x, y; cin >> v >> x >> y;
            if(check_name.find(v) != check_name.end()) flag = false;
            else {
              check_name.insert(v);
              name.push(v);
              if(x[0] >= '0' && x[0] <= '9' && y[0] == 'n') {
                if(!alone) tempO++;
                finallyO = max(finallyO, tempO);
              } else if(x[0] == 'n' && y[0] >= '0' && y[0] <= '9'
                        || getNumber(x) > getNumber(y))
                        alone = true;
            }
          }
        }
        if(EFs || !flag) puts("ERR");
        else if(getO(o) == finallyO) puts("Yes");
        else puts("No");
      }
    
      return 0;
    }
    
    
  • 相关阅读:
    python-单链表的实现
    python-树形结构和遍历
    python四种简单排序
    python数据类型
    python安装和配置
    Js 中的false,零值,null,undefined和空字符串对象
    console和chrom-tool
    js中声明Number的五种方式
    vue下拉搜索
    canvas猜数游戏
  • 原文地址:https://www.cnblogs.com/fromneptune/p/12222213.html
Copyright © 2011-2022 走看看