zoukankan      html  css  js  c++  java
  • UVa 673 Parentheses Balance

      用栈进行模拟就行了,不过要考虑空行的情况,该开始就没考虑数据有空行的情况,认为不可能,WA了一次,果然没什么理所当然啊。

      代码如下:

    View Code
     1 #include <cstdio>
     2 #include <stack>
     3 #include <cstring>
     4 using namespace std;
     5 
     6 const int maxn = 150;
     7 
     8 int main()
     9 {
    10 #ifdef LOCAL
    11     freopen("in", "r", stdin);
    12 #endif
    13     int n;
    14     char data[150];
    15     stack<char> s;
    16     scanf("%d", &n);
    17     getchar();
    18     while(n--)
    19     {
    20         fgets(data, maxn, stdin);
    21         int len = strlen(data);
    22         if(len == 1)
    23         {
    24             printf("Yes\n");
    25             continue;
    26         }
    27         len--;
    28         while(!s.empty())   s.pop();
    29         for(int i = 0; i < len; i++)
    30         {
    31             if(!s.empty() && ((data[i] == ')' && s.top() == '(') || (data[i] == ']' && s.top() == '[')))
    32                 s.pop();
    33             else s.push(data[i]);
    34         }
    35         if(s.empty())   printf("Yes\n");
    36         else printf("No\n");
    37     }
    38     return 0;
    39 }
  • 相关阅读:
    安全
    请求
    使用 Fetch
    安全
    script
    PWA
    link(外部资源关系)
    base(根URL)
    缓存
    IndexedDB基本概念
  • 原文地址:https://www.cnblogs.com/xiaobaibuhei/p/3022104.html
Copyright © 2011-2022 走看看