Skip to content

Commit

Permalink
ANARC09A no need of stack
Browse files Browse the repository at this point in the history
  • Loading branch information
ramjeetsaran committed Sep 23, 2015
1 parent 159dee7 commit 1c13b83
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
38 changes: 38 additions & 0 deletions ANARC09A.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//DATE: 22/09/2015
//Author: Ramjeet Saran
//http://www.spoj.com/problems/GCD2/

#include <bits/stdc++.h>

#define gc getchar_unlocked
#define pc putchar_unlocked
# define MAX(a,b) a>b ? a : b;
# define MIN(a,b) a<b ? a : b;
# define lli long long int
# define ull unsigned long long int

using namespace std;

int compute(string input){
int open = 0, close = 0;
int len = input.length();
for(int i = 0; i < len; i++){
if(input[i] == '{')
open++;
if(input[i] == '}'){
if(open)
open--;
else close++;
}
}
return open / 2 + close / 2 + open % 2 + close % 2;
}
int main(){
string input;
int i = 1;
cin>>input;
while(input[0] != '-'){
cout<<i++<<". "<<compute(input)<<endl;
cin>>input;
}
}
1 change: 1 addition & 0 deletions Readme
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,4 @@ http://www.spoj.com/users/raj94/
67) DOTAA
68) MIXTURES
69) GCD2
70) ANARC09A

0 comments on commit 1c13b83

Please sign in to comment.