#include <stdio.h>
#include <string.h>
char stack[500];
int top=-1;

int main() {
    char line[105];

    while (1) {
        // 1. 한 줄 전체를 입력받음 (공백 포함)
        if(fgets(line, sizeof(line),stdin)==NULL) break;
        // 2. 종료 조건: 온점 하나만 들어온 경우
        // fgets는 줄바꿈(\n)까지 같이 가져오므로 체크가 필요함
        if(line[0]=='.' && (line[1] == '\n' || line[1] == '\0' || line[1] == '\r')) {
            break;
        }
        top=-1;
        int flag=1;
        for(int i=0; line[i]!='.'; i++) {
            int x=line[i];
            if(x=='(' || x=='[') {
                stack[++top]=x;
            } else if(x==')') {
                if (top==-1 || stack[top--]!='(') {
                    flag=0;
                    break;
                }
            }   else if(x==']') {
                if (top==-1 || stack[top--]!='[') {
                    flag=0;
                    break;
                }
            }
        }

        if(top==-1 && flag==1) printf("yes\n");
        else printf("no\n");
        top=-1;
    }
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: