Scaena Felix

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 101    Accepted Submission(s): 49

Problem Description
Given a parentheses sequence consist of '(' and ')', a modify can filp a parentheses, changing '(' to ')' or ')' to '('.

If we want every not empty <b>substring</b> of this parentheses sequence not to be "paren-matching", how many times at least to modify this parentheses sequence?

For example, "()","(())","()()" are "paren-matching" strings, but "((", ")(", "((()" are not.

 
Input
The first line of the input is a integer T, meaning that there are T test cases.

Every test cases contains a parentheses sequence S only consists of '(' and ')'.

1≤|S|≤1,000.

 
Output
For every test case output the least number of modification.
 
Sample Input
3
()
((((
(())
 
Sample Output
1
0
2
题解:水题。。。。匹配括号的个数。。。
代码:
 #include<stdio.h>
#include<stack>
using namespace std;
const int MAXN=;
char m[MAXN];
int main(){
int T;
scanf("%d",&T);
while(T--){
stack<char>st;
scanf("%s",m);
int k=;
for(int i=;m[i];i++){
if(m[i]=='(')st.push(m[i]);
else if(!st.empty())st.pop(),k++;
}
printf("%d\n",k);
}
return ;
}

hdoj Scaena Felix的更多相关文章

  1. HDU 5479 Scaena Felix

    水题,括号匹配,有几对匹配了,答案就是那个... #include<cstdio> #include<cstring> #include<cmath> #inclu ...

  2. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  4. HDOJ 1326. Box of Bricks 纯水题

    Box of Bricks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  5. HDOJ 1004 Let the Balloon Rise

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

  6. hdoj 1385Minimum Transport Cost

    卧槽....最近刷的cf上有最短路,本来想拿这题复习一下.... 题意就是在输出最短路的情况下,经过每个节点会增加税收,另外要字典序输出,注意a到b和b到a的权值不同 然后就是处理字典序的问题,当松弛 ...

  7. HDOJ(2056)&HDOJ(1086)

    Rectangles    HDOJ(2056) http://acm.hdu.edu.cn/showproblem.php?pid=2056 题目描述:给2条线段,分别构成2个矩形,求2个矩形相交面 ...

  8. 继续node爬虫 — 百行代码自制自动AC机器人日解千题攻占HDOJ

    前言 不说话,先猛戳 Ranklist 看我排名. 这是用 node 自动刷题大概半天的 "战绩",本文就来为大家简单讲解下如何用 node 做一个 "自动AC机&quo ...

  9. 最近点对问题 POJ 3714 Raid && HDOJ 1007 Quoit Design

    题意:有n个点,问其中某一对点的距离最小是多少 分析:分治法解决问题:先按照x坐标排序,求解(left, mid)和(mid+1, right)范围的最小值,然后类似区间合并,分离mid左右的点也求最 ...

随机推荐

  1. tr删除替换详解

    tr(translate缩写)主要用于删除文件中的控制字符,或进行字符转换. 语法:tr  [–c/d/s/t] [SET1] [SET2]    #SET1: 字符集1: SET2:字符集2 -c: ...

  2. Prepare Python environment and install selenium.

    1, Install python and selenium. I use python 3.5, the following is the example 1.)    Python downloa ...

  3. delphi高手突破学习笔记之面向对象类和对象的本质

    知识点1:堆和栈 每个应用程序可以获得的内存空间分为两种:堆(heap)和栈(stack). 堆又称为“自由存储区”,其中的内存空间的分配与释放是必须由程序员来控制的.例如,用GetMem函数获取了一 ...

  4. IE9下报错,错误: “JSON”未定义

    今天在公司运行的代码好好的,但是拿回家里以后就报错了 结果是IE9,没有设为兼容模式,唉,微软导出都是坑啊.

  5. ViewTreeObserver简介

    Android ViewTreeObserver简介 一.结构 public final class ViewTreeObserver extends Object java.lang.Object ...

  6. 如何在IE8下调试OCX控件

    第一种方式 多进程模式下, 在IE8打开web页面, 然后在调试菜单选择附加到进程, 这时看到2个IE进程, 选择没有带标题的, 也就是主进程, 就可以正常调试了. 此方式比较麻烦, 不能F5直接启动 ...

  7. js预处理图片个人见解1

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. Python入门-函数的使用到程序的公布安装

    Python入门-函数的使用到Python的公布安装 本文主要适合有一定编程经验,至少掌握一门编程语言的人查看. 文中样例大多都是简单到认识英文单词就能看懂的水平,主要讲的是Python的总体使用方法 ...

  9. 假设写一个android桌面滑动切换屏幕的控件(一)

    首先这个控件应该是继承ViewGroup: 初始化: public class MyGroup extends ViewGroup{ private Scroller mScroller; priva ...

  10. xcode - 触摸移动

    第一步 创建一个UIView类  命名MoveView #import "MoveView.h" @implementation MoveView /** 移动事件 */ -(vo ...