728x90
반응형
4949번 균형잡힌 세상
문제 풀이
#include <iostream>
#include <string>
#include <stack>
using namespace std;
int main(void)
{
while (1)
{
string str;
getline(cin, str);
if (str == ".")
{
break;
}
stack<char> st;
int ck = 0;
for (int i = 0; i < str.length(); i++)
{
if (str[i] == 40 || str[i] == 91)
{
st.push(str[i]);
}
else if (str[i] == 41)
{
if (!st.empty() && st.top() == 40)
{
st.pop();
}
else
{
ck = 1;
}
}
else if (str[i] == 93)
{
if (!st.empty() && st.top() == 91)
{
st.pop();
}
else
{
ck = 1;
}
}
}
if (st.empty() && ck == 0)
{
printf("yes\n");
}
else
{
printf("no\n");
}
}
}
flag를 줄때 bool 타입을 써야겠다.
728x90
반응형
'자라는 개발자 > 문제풀이' 카테고리의 다른 글
백준 C++ 2164번 카드2 (0) | 2021.12.06 |
---|---|
백준 C 1259번 팰린드롬수 (1) | 2021.12.03 |
백준 C 2775번 부녀회장이 될테야 (0) | 2021.11.30 |
백준 C++ 10814번 나이순정렬 (0) | 2021.11.30 |
백준 C 23739번 벼락치기 (1) | 2021.11.29 |