-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
159dee7
commit 1c13b83
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,3 +71,4 @@ http://www.spoj.com/users/raj94/ | |
67) DOTAA | ||
68) MIXTURES | ||
69) GCD2 | ||
70) ANARC09A |