강의

멘토링

커뮤니티

Inflearn Community Q&A

drcaesarclown1519's profile image
drcaesarclown1519

asked

10-Week C++ Coding Test | Algorithm Coding Test

2-O

2-O 맞은거 같은데 왜 틀릴까요? ㅠㅠ

Written on

·

355

0

#include<iostream>
#include<string>
#include<stack>
using namespace std;
bool check(string s){
    stack<char> stk;
    for(char c : s){
        if(c=='(')stk.push(c);
        if(c=='[')stk.push(c);
        if(c==')'){
            if(stk.empty()||stk.top()=='['){
                return false;
            }
            stk.pop();
        }
        if(c==']'){
            if(stk.empty()||stk.top()=='('){
                return false;
            }
            stk.pop();
        }
    }
    if(stk.size())return false;
    else return true; 
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    while(1){
        string str;
        getline(cin,str);
        if(str==".")break;
        if(check(str))cout<< "yes\n";
        else cout<<"no\n";
    }
    return 0;
}
c++코딩-테스트

Answer 3

1

I can't see any other problems, maybe my technology is not up to standard.ChatGPT

0

kundol님의 프로필 이미지
kundol
Instructor

아 ㅎㅎ 해결하셨다니 다행이네요 ㅎㅎ 또 질문있으시면 질문주세요 ㅎㅎ

0

맞네요 죄송합니다 제가 제출을 잘못해서 그런거네요

drcaesarclown1519's profile image
drcaesarclown1519

asked

Ask a question