Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- 10026번
- Operating System.
- 이펙티브코틀린
- 우아한 테크 세미나
- Window-Via-c/c++
- HTTP
- 제프리리처
- FIFO paging
- n타일링2
- 우아한레디스
- BOJ
- inflearn
- 윤성우 저자
- 김영한
- 토마토
- TCP/IP
- 스프링 입문
- 에러핸들링
- Four Squares
- 스프링 핵심 원리
- 2475번
- redis
- Spring
- 열혈 tcp/ip 프로그래밍
- C#
- 열혈 TCP/IP 소켓 프로그래밍
- 운영체제
- Operating System
- OS
- C++
Archives
- Today
- Total
나의 브을로오그으
[c++] 4949번 : 균형잡힌 세상 본문
https://www.acmicpc.net/problem/4949
#include <iostream>
#include <string>
#include <stack>
using namespace std;
#define NO 0
#define YES 1
bool isCheckPair(char c1, char c2)
{
if (c1 == '(' && c2 == ')') return true;
if (c1 == '[' && c2 == ']') return true;
return false;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
stack<char> st;
const char* result[2] = { "no", "yes"};
string buffer;
while (true)
{
while (!st.empty()) { st.pop(); }
getline(cin, buffer);
if (buffer.length() == 1 && buffer[0] == '.') break;
int flag = YES;
for(int i = 0 ; i < buffer.length(); ++i)
{
if (buffer[i] == '(' || buffer[i] == '[')
{
st.push(buffer[i]);
}
else if (buffer[i] == ')' || buffer[i] == ']')
{
if (st.empty() == true)
{
flag = NO;
break;
}
else
{
if (isCheckPair(st.top(), buffer[i]) == true)
{
st.pop();
}
else
{
flag = NO;
break;
}
}
}
}
if (st.empty() == false) flag = NO;
cout << result[flag] << '\n';
}
return 0;
}
'알고리즘 > BaekJoon' 카테고리의 다른 글
[c++] 9012번 : 괄호 (0) | 2022.05.04 |
---|---|
[c++] 7568번 : 덩치 (0) | 2022.05.04 |
[c++] 4153번 : 직각삼각형 (0) | 2022.04.30 |
[c++] 2869번 : 달팽이는 올라가고 싶다 (0) | 2022.04.30 |
[c++] 2839번 : 설탕 배달 (0) | 2022.04.29 |