강의

멘토링

커뮤니티

Inflearn Community Q&A

su88888888941670's profile image
su88888888941670

asked

Introduction to Algorithm Problem Solving for IT Employment (with C/C++): Coding Test Preparation

54. Correct parentheses (using STL stack data structure)

질문있습니다!

Written on

·

188

0

#include <iostream>

#include <vector>

#include <algorithm>

#include <string>

#include <stack>

using namespace std;

int main() {

char str[30];

scanf("%s",&str);

stack <char> s;

for(int i = 0; str[i] != '\0'; i++){

if(str[i] == '(') s.push(str[i]);

else {

if(!s.empty()) s.pop();

else {

printf("NO");

exit(0);

}

}

}

if (s.empty()) printf("YES");

else printf("NO");

return 0;

}

선생님 강의와 조금 다르게 exit(0)를 사용해 바로 종료시켰는데 이래도 되는거죠?

exit(0) 함수는 원래 코딩에서 잘 사용안하는건가요?

C++코테 준비 같이 해요!

Answer 2

0

감사합니다!

0

codingcamp님의 프로필 이미지
codingcamp
Instructor

안녕하세요^^

사용하는 것을 금하는 회사도 있는 걸로 알고있습니다. 하지만 저는 자주 사용합니다. 

su88888888941670's profile image
su88888888941670

asked

Ask a question