Skip to content

Instantly share code, notes, and snippets.

@lackofdream
Created April 18, 2015 02:59
Show Gist options
  • Select an option

  • Save lackofdream/3febe9e3293e6839d15d to your computer and use it in GitHub Desktop.

Select an option

Save lackofdream/3febe9e3293e6839d15d to your computer and use it in GitHub Desktop.
HDU1870
#include <cstdio>
#include <ctime>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <vector>
#include <fstream>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <string>
#define MAX(a,b) (a>b?a:b)
#define sd(x) scanf("%d",&x)
#define sdd(a,b) scanf("%d%d",&a,&b)
#define sddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define slflf(x,y) scanf("%lf%lf",&x,&y)
#define abs(x) (x<0?(-x):x)
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
using namespace std;
char input[1100];
stack<char>beforeB;
stack<char>afterB;
int main()
{
while(gets(input))
{
while(!beforeB.empty()) beforeB.pop();
while(!afterB.empty()) afterB.pop();
int len = strlen(input);
bool hasBAppeared = false;
int cnt=0;
for (int i=0;i<len;i++)
{
if (!hasBAppeared)
{
if (input[i]=='(') beforeB.push('(');
else if (input[i]==')') beforeB.pop();
else hasBAppeared=true;
}
else
{
if (input[i]=='(') afterB.push('(');
else
{
if (!afterB.empty()) afterB.pop();
else {beforeB.pop();cnt++;}
}
}
}
cout << cnt << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment