博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdoj Scaena Felix
阅读量:7076 次
发布时间:2019-06-28

本文共 1322 字,大约阅读时间需要 4 分钟。

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
题解:水题。。。。匹配括号的个数。。。
代码:
1 #include
2 #include
3 using namespace std; 4 const int MAXN=1100; 5 char m[MAXN]; 6 int main(){ 7 int T; 8 scanf("%d",&T); 9 while(T--){10 stack
st;11 scanf("%s",m);12 int k=0;13 for(int i=0;m[i];i++){14 if(m[i]=='(')st.push(m[i]);15 else if(!st.empty())st.pop(),k++;16 }17 printf("%d\n",k);18 }19 return 0;20 }

 

转载地址:http://sodml.baihongyu.com/

你可能感兴趣的文章
Scala的基本语法总结
查看>>
【OpenCV】图像转成YUV420 I420格式
查看>>
PLSQL中隐式打开cursor的小例子
查看>>
设计模式与足球
查看>>
高性能网络使DNS DDoS无损防护成为可能
查看>>
RDIFramework.NET ━ .NET快速信息化系统开发框架 V3.2->WinForm版本新增新的角色授权管理界面效率更高、更规范...
查看>>
JAVAC 命令使用方法
查看>>
9.3. Yate - Yet Another Telephony Engine (includes SIP to H.323 translation)
查看>>
利用python/pandas/numpy做数据分析(三)-透视表pivot_table
查看>>
SQL Server 数据库项目
查看>>
Windows7下pip安装包报错:Microsoft Visual C++ 9.0 is required Unable to find vcvarsall.bat
查看>>
陈正冲老师讲c语言之内存的申请malloc() 和释放free()
查看>>
TortoiseSVN比较工具设置为BeyondCompare 4
查看>>
大会 | SEE Conf:Ant Design 3.0 背后的故事
查看>>
js中substring与substr 使用方法
查看>>
[LeetCode] Serialize and Deserialize Binary Tree 二叉树的序列化和去序列化
查看>>
開始折腾cocos2d-x,使用批处理来创建项目
查看>>
第 30 章 GNU Development Tools
查看>>
Flex Air开发SQLite小结,SQLite开发工具及SQLite与Sql Server的语法差异汇总
查看>>
ABBYY FineReader OCR图片文字识别软件安装应用
查看>>