An important task when processing arithmetic expressions is to mach delimiters.

We can use Stack to solve this problem.

def is_matched(expr):
left='({['
right=')}]' S=ArrayStack() for c in expr:
if c in left:
S.push(c)
elif c in right:
if S.is_empty():
return False
if right.index(c)!=left.index(S.pop()):
return False
return S.is_empty()

  

[Data Structure] An Algorithm for Matching Delimiters的更多相关文章

  1. <Data Structure and Algorithm>排序算法

    排序稳定:如果两个数相同,对他们进行的排序结果为他们的相对顺序不变.例如A={1,2,1,2,1}这里排序之后是A = {1,1,1,2,2} 稳定就是排序后第一个1就是排序前的第一个1,第二个1就是 ...

  2. [Algorithm] Heap data structure and heap sort algorithm

    Source, git Heap is a data structure that can fundamentally change the performance of fairly common ...

  3. [Algorithm] Trie data structure

    For example we have an array of words: [car, done, try, cat, trie, do] What is the best data structu ...

  4. [Algorithm] JavaScript Graph Data Structure

    A graph is a data structure comprised of a set of nodes, also known as vertices, and a set of edges. ...

  5. [LeetCode] Add and Search Word - Data structure design 添加和查找单词-数据结构设计

    Design a data structure that supports the following two operations: void addWord(word) bool search(w ...

  6. HDU5739 Fantasia(点双连通分量 + Block Forest Data Structure)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5739 Description Professor Zhang has an undirect ...

  7. hdu-5929 Basic Data Structure(双端队列+模拟)

    题目链接: Basic Data Structure Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 65536/65536 K (Ja ...

  8. CDOJ 483 Data Structure Problem DFS

    Data Structure Problem Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/proble ...

  9. HDU 5929 Basic Data Structure 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)

    Basic Data Structure Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

随机推荐

  1. VSS迁移详细教程

    本文默认迁移机和目标机已是安装好VSS服务,如果没装好参见VSS+SourceAnywhere for VSS搭建版本控制系统教程 如果你只想以最快的速度迁移库而并不关心VSS的一些操作使用,那么可直 ...

  2. MySQL修改root密码教程

    1.记得密码但想要更新密码 mysql -uroot -p #使用当前密码登录mysql update MySQL.user set password=PASSWORD('新密码') where Us ...

  3. windows的网上邻居

    要说以前中学最怕上什么课就是电脑课,要说电脑印象最深的是什么软件就是总摆在桌面又听不懂又点进去什么都没有的“网上邻居”. “网上邻居”指的是同一局域网内在线的的电脑,更简单些就是连在同一路由器中开机的 ...

  4. Qt贴图实现地图标记效果

    #include "wgtmap.h" #include "ui_wgtmap.h" #include <QPainter> #define IMG ...

  5. 如何让一个div水平和垂直居中对齐

    以下方法来自百度知道:https://zhidao.baidu.com/question/558984366971173044.html 方法1: .parent { width: 800px; he ...

  6. VIM编辑配置文件基本操作

    vim  /etc/apt/sources.list 按insert键进入编辑状态 编辑完成以后按ESC退出编辑状态 输入 ":"进入命令状态,常用命令: 1.W:write ,写 ...

  7. Win10系列:VC++调用自定义组件2

    (2)C#调用WinRT组件 在解决方案资源管理器中右键点击解决方案图标,选择添加一个Visual C#的Windows应用商店的空白应用程序项目,并命名为FileCS.接着右键点击FileCS项目的 ...

  8. learning ddr mode reigsters

    For application flexibility, various functions, features, and modes are programmable in four Mode Re ...

  9. day3-PyCharm 断点 调试模式

    上篇学习了Python的工具选择,PyCharm的基本设置,简单的了解了下PyCharm的调试模式,今天主要学习下PyCharm的调式模式,在以后的开发中是一个非常重要的工具. [运行]和[调试]前的 ...

  10. dell win10 productkey