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
- 스프링부트팔로잉
- 출처 문어박사
- 스프링부트
- 스프링구독
- 출처 메타코딩
- 출처 노마드코더
- centos도커설치
- 스프링부트api
- 출처 따배도
- 파이썬sort
- 스프링부트구독취소
- 스프링사진
- WAS웹서버
- dockerinstall
- 멀티폼
- 스프링이미지업로드
- 도커설치하는법
- springboot_exception_handler
- ssh도커설치
- 스프링부트서버에사진전송
- 스프링부트팔로우취소
- 스프링부트사진올리기
- vm도커설치하는법
- 서버에도커설치
- 우분투도커설치
- 스프링익셉션처리
- 인스타클론
- 스프링부트중복예외처리
- 스프링사진업로드
- 출처 코딩셰프
Archives
- Today
- Total
MakerHyeon
[백준] 9012번 괄호 (Python,C++) 본문
https://www.acmicpc.net/problem/9012
9012번: 괄호
괄호 문자열(Parenthesis String, PS)은 두 개의 괄호 기호인 ‘(’ 와 ‘)’ 만으로 구성되어 있는 문자열이다. 그 중에서 괄호의 모양이 바르게 구성된 문자열을 올바른 괄호 문자열(Valid PS, VPS)이라고
www.acmicpc.net
릿코드 문제와 똑같구만...
SOLUTION CODE
# PYTHON
for _ in range(int(input())):
stk = []
isVPS = True
for ch in input():
if ch == '(':
stk.append(ch)
else:
if stk: # 스택 비어있지않을때
stk.pop()
else: # 스택 비어있으면 False
isVps = False
break
if stk:
isVPS = False
print('YES' if isVPS else 'NO')
# C++
#include <iostream>
#include <stack>
using namespace std;
string isVPS(string s){
stack<char> stk;
for(int i=0; i< s.size();i++){
if(s[i] == '('){
stk.push('(');
}
else {
if(s.empty()) return "NO";
stk.pop();
}
}
string ans = (s.empty())? "YES" : "NO";
return ans;
}
int main(void){
ios::sync_with_stdio(0);
cin.tie(0);
int input;
string input_s;
cin >> input;
for(int i=0;i<input;i++){
cin>>input_s;
cout<< isVPS(input_s)<<'\n';
}
}
'Algorithm > backjoon' 카테고리의 다른 글
[백준] 1449번 수리공 항승 (0) | 2023.02.13 |
---|---|
[백준] 2309번 일곱 난쟁이 (Python,C++) (0) | 2023.02.12 |
[백준] 11286번 절댓값 힙 (Python,C++) (0) | 2023.01.27 |
[백준] 2164번 카드2 (Python,C++) (0) | 2023.01.27 |
[백준] 1931번 회의실 배정 (Python,C++) (0) | 2023.01.03 |
Comments