알고리즘/SWEA

[SWEA 1218] 괄호 짝짓기

히더 2018. 8. 10. 15:28

출처 : https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV14eWb6AAkCFAYD


#include <iostream>

#include <algorithm>

#include <memory.h>

using namespace std;


int N,result;

int check[4];


int main()

{

int T; int t=1;

T = 10;

while (T--)

{

cin >> N; result = 1;

fill(check, check + 4, 0);

for (int i = 0; i < N; i++)

{

char c; cin >> c;

if (c == '(') check[0] += 1;

else if (c == ')') check[0] -= 1;

else if (c == '[') check[1] += 1;

else if (c == ']') check[1] -= 1;

else if (c == '{') check[2] += 1;

else if (c == '}') check[2] -= 1;

else if (c == '<') check[3] += 1;

else if (c == '>') check[3] -= 1;

}

for (int i = 0; i < 4; i++)

{

if (check[i] != 0) result = 0;

}


cout << "#" << t++ << " " << result << endl;

}


return 0;

}