Seinfeld(杭电3351)
Seinfeld
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1382    Accepted Submission(s): 683
You’re given a non empty string made in its entirety from opening and closing braces. Your task is to find the minimum number of “operations” needed to make the string stable. The definition for being stable is as follows:
1. An empty string is stable.
2. If S is stable, then {S} is also stable.
3. If S and T are both stable, then ST (the concatenation of the two) is also stable.
All of these strings are stable: {}, {}{}, and {{}{}}; But none of these: }{, {{}{, nor {}{.
The only operation allowed on the string is to replace an opening brace with a closing brace, or visa-versa.
The last line of the input is made of one or more ’-’ (minus signs.)
k. N
Where k is the test case number (starting at one,) and N is the minimum number of operations needed to convert the given string into a balanced one.
Note: There is a blank space before N.
}{
{}{}{}
{{{}
---
1. 2
2. 0
3. 1#include<stdio.h>
#include<string.h>
int main()
{
int k=1;
int a,t,i,len;
char str[2010];
while(gets(str)&&str[0]!='-')
{
int a=t=0;
len=strlen(str);
for(i=0;i<len;i++)
{
if(str[i]=='{')
{
t++;
}
else
{
if(t)
{
t--;
}
else
{
t++;
a++;
}
}
}
a=a+t/2;
printf("%d. %d\n",k,a);
k++;
}
return 0;
}
Seinfeld(杭电3351)的更多相关文章
- 杭电ACM分类
		
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
 - acm入门  杭电1001题  有关溢出的考虑
		
最近在尝试做acm试题,刚刚是1001题就把我困住了,这是题目: Problem Description In this problem, your task is to calculate SUM( ...
 - 杭电acm 1002 大数模板(一)
		
从杭电第一题开始A,发现做到1002就不会了,经过几天时间终于A出来了,顺便整理了一下关于大数的东西 其实这是刘汝佳老师在<算法竞赛 经典入门 第二版> 中所讲的模板,代码原封不动写上的, ...
 - 杭电OJ——1198 Farm Irrigation (并查集)
		
畅通工程 Problem Description 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇.省政府"畅通工程"的目标是使全省任何两个城镇间都可 ...
 - 高手看了,感觉惨不忍睹——关于“【ACM】杭电ACM题一直WA求高手看看代码”
		
按 被中科大软件学院二年级研究生 HCOONa 骂为“误人子弟”之后(见:<中科大的那位,敢更不要脸点么?> ),继续“误人子弟”. 问题: 题目:(感谢 王爱学志 网友对题目给出的翻译) ...
 - C#利用POST实现杭电oj的AC自动机器人,AC率高达50%~~
		
暑假集训虽然很快乐,偶尔也会比较枯燥,,这个时候就需要自娱自乐... 然后看hdu的排行榜发现,除了一些是虚拟测评机的账号以外,有几个都是AC自动机器人 然后发现有一位作者是用网页填表然后按钮模拟,, ...
 - 杭电ACM2076--夹角有多大(题目已修改,注意读题)
		
杭电ACM2076--夹角有多大(题目已修改,注意读题) http://acm.hdu.edu.cn/showproblem.php?pid=2076 思路很简单.直接贴代码.过程分析有点耗时间. / ...
 - 杭电ACM2092--整数解
		
杭电ACM2092--整数解 分析 http://acm.hdu.edu.cn/showproblem.php?pid=2092 一个YES,一个Yes.试了10几次..我也是无语了..哪里都不 ...
 - 杭电2034——人见人爱A-B
		
#include <stdio.h> #include <algorithm> using namespace std; int main () { int a[110],b[ ...
 
随机推荐
- Windows杂技
			
WINDOWS下 ,在某目录下按住shift加鼠标右键,可以直接有当前目录的dos窗口 win10不能用 解决办法是在当前文件夹的地址栏输入cmd然后回车 发现Powershell可以当作dos执行相 ...
 - Linux系统维护管理命令及vim编辑器
			
系统维护管理命令date.clear $>>date //显示或修改系统时间与日期. //%H:小时 %M:分钟 %S:秒 %Y完整年份 %d:日 %m:月份 eg: date " ...
 - kb-07线段树-05-区间整体修改查询;(水)
			
/* */ #include<iostream> #include<cstring> #include<cstdio> using namespace std; s ...
 - Educational Codeforces Round 10——B. z-sort
			
B. z-sort time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...
 - [暑假集训--数位dp]LightOj1205 Palindromic Numbers
			
A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the sam ...
 - DispatcherServlet与ContextLoaderListener的对比
			
1. 从DispatcherServlet和ContextLoaderListener的初始化过程可以看出,二者分别会生成一个WebApplicationContext,且以不同的attrName注册 ...
 - Codeforces989E. A Trance of Nightfall
			
$n \leq 200$个平面上的点,$q \leq 200$次询问:重复操作$m \leq 10000$次,到达点$x$的概率最大是多少.操作:一开始选点$P$,不一定要是给定点,可以是平面上任一点 ...
 - scss  侧边栏_图片
			
html <!doctype html><html lang="zh-CN"><head> <meta charset="UTF ...
 - es6总结(四)--对象
 - windows8.1如何分盘
			
磁盘分区首先要弄明白磁盘物理顺序与逻辑顺序的区别,在[磁盘管理]界面,所显示的前后顺序为物理顺序,这是磁盘上实实在在的物理位置,如下图2的电脑磁盘物理顺序为CFDE.在[资源管理器]界面,所显示的顺序 ...