Parentheses Matching(栈)
来源:互联网 发布:mysql 好友关系表 编辑:程序博客网 时间:2024/06/15 06:21
题目1 : Parentheses Matching
时间限制:10000ms
单点时限:1000ms
内存限制:256MB
- 样例输入
(())()()
- 样例输出
1 4 2 3 5 6 7 8
这道题给了我栈的另外一种用法,原来配对括号的时候,栈还可以压入它的下标,最后排下序就好了。
#include<stdio.h>#include<algorithm>#include<math.h>#include<string.h>#include<stack>using namespace std;char s[100005];struct A{ int q,p;}a[50005];bool cmp(A m,A n){ return m.q<n.q;}int main(){ gets(s); int len=strlen(s); stack <int>t; int l=0; for(int i=0;i<len;i++) { if(s[i]=='(') t.push(i+1); else { a[l].q=t.top(); a[l].p=i+1; t.pop(); l++; } } sort(a,a+l,cmp); for(int i=0;i<l;i++) { printf("%d %d\n",a[i].q,a[i].p); }}
描述
Given a string of balanced parentheses output all the matching pairs.
输入
A string consisting of only parentheses '(' and ')'. The parentheses are balanced and the length of the string is no more than 100000.
输出
For each pair of matched parentheses output their positions in the string.
0 0
- Parentheses Matching(栈)
- Uva673 Parentheses Balance(栈)
- 20. Valid Parentheses(栈)
- uva 673 Parentheses Balance(栈)
- Parentheses Balance(括号匹配)--栈
- Valid Parentheses (栈的符号匹配)
- LeetCode 之 Longest Valid Parentheses(栈)
- uva 673 Parentheses Balance(栈)
- UVA - 673 - Parentheses Balance(栈)
- leetcode_c++:栈:Valid Parentheses(020)
- UVA 673 Parentheses Balance ( 栈 + 坑)
- 阻抗匹配(Impedance Matching )
- String Matching(poj1580)
- Matching
- Parentheses Balance-栈
- Leetcode 栈 Valid Parentheses
- 栈 Valid Parentheses
- [leetcode][栈] Valid Parentheses
- Android代码规范----按钮单击事件的四种写法
- django+apache+windows环境,css丢失解决办法
- eclipse中如何修改代码字体
- String,StringBuilder,StringgBuffer三个类的区别?
- dubbo2.5-spring4-mybastis3.2-springmvc4-mongodb3.4-redis3.2整合(一)Dubbo的使用
- Parentheses Matching(栈)
- matplot 基本用法
- ubuntu 出现GPG Error的问题
- Java中静态代码块的用法 static用法详解
- 7
- php 优化页面输出,兼容搜索引擎机器人访问的实例
- Android组件---四大布局的属性详解
- 查找包中的某资源调用
- 随机变量的函数的分布