所属分类:
Windows编程
开发工具:C++
文件大小:1KB
下载次数:2
上传日期:2014-03-11 20:50:40
说明: 括号匹配(二)
时间限制:1000 ms | 内存限制:65535 KB
难度:6
描述
给你一个字符串,里面只包含"(",")","[","]"四种符号,请问你需要至少添加多少个括号才能使这些括号匹配起来。
如:
[]是匹配的
([])[]是匹配的
((]是不匹配的
([)]是不匹配的
输入
第一行输入一个正整数N,表示测试数据组数(N<=10)
每组测试数据都只有一行,是一个字符串S,S中只包含以上所说的四种字符,S的长度不超过100
输出
对于每组测试数据都输出一个正整数,表示最少需要添加的括号的数量。每组测试输出占一行
样例输入
4
[]
([])[]
((]
([)]样例输出
0
0
3
2
(Matching brackets (two)
Time Limit: 1000 ms | Memory Limit: 65535 KB
Difficulty: 6
Description
Give you a string, which contains only "(", ")", "[", "]" Four symbols, what you need to add at least the number of brackets to make these brackets match up.
Such as:
[] Is matched
([]) [] Is matched
((] Is a mismatch
([)] Is a mismatch
Enter
The first line enter a positive integer N, the number of test data sets (N <= 10)
Each test is only one line, is a string S, S contains only four characters mentioned above, the length does not exceed 100 S
Export
For each test data outputs a positive integer indicating the minimum number needed to add parentheses. Each test output per line
Sample Input
4
[]
([]) []
((]
([)] Sample Output
0
0
3
2)
文件列表:
ProgramA.cpp,1075,2013-03-30