Go: package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Buffer(make([]byte, 0), 1000000009)

	for {
		var s string
		s = nextString()
		if s == "." {
			break
		}
		var st []byte
		is_valid := true

		for _, value := range s {
			if value == '(' {
				st = append(st, byte(value))
			}
			if value == '[' {
				st = append(st, byte(value))
			}
			if value == ')' {
				if len(st) == 0 || st[len(st)-1] != '(' {
					is_valid = false
					break
				} else {
					st = st[:len(st)-1]
				}
			}
			if value == ']' {
				if len(st) == 0 || st[len(st)-1] != '[' {
					is_valid = false
					break
				} else {
					st = st[:len(st)-1]
				}
			}
		}
		if len(st) != 0 {
			is_valid = false
		}
		if is_valid {
			fmt.Println("yes")
		} else {
			fmt.Println("no")
		}
	}
}

C++: #include <iostream>
#include <deque>
using namespace std;
bool solve(string str){
	deque<char> q;
	for(int i=0; i<str.length(); ++i){
		if(str[i]==')' || str[i]==']'){
			if(q.empty())	return false;
			char c=q.back();
			if(str[i]!=c)	return false;
			q.pop_back();
		}else if(str[i]=='(')	q.push_back(')');
		else if(str[i]=='[')	q.push_back(']');
	}
	return q.empty();
}
int main(){
	string str;
	while(getline(cin,str)){
		if(str==".")	break;
		cout << (solve(str)? "yes": "no") << endl;
	}
}

C++: #include <bits/stdc++.h>
#include <stdio.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
//typedef tuple<int, int, int> T;
 
const ll MOD=1e9+7;
const ll INF=1e18;
 
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};


bool ch[150];
int num[150];

int main(){
    while(true){
    //    char data[120];
        string data;
        getline(cin,data);
    //    gets(data);
        if(data[0] == '.') break;
      //  int len = strlen(data);
        int len = data.length();
        int sum = 0;
        for(int i = 0;i < len;i++){
            int add = 0;
            switch(data[i]){
                case '(':
                    add = -1;
                    break;
                case '[':
                    add = -2;
                    break;
                case ')':
                    add = 1;
                    break;
                case ']':
                    add = 2;
                    break;
            }
            if(add == 0)continue;
            ch[sum] = false;
            num[sum++] = add;
        }
        int ans = 1,max = sum;
        while(true){
            if(sum % 2 != 0){ ans = 0; break;}
            if(sum == 0) break;
            int check = 0;
            for(int i = 1;i < sum;i++){
                int a,b;
                int count = 0;
                for(int j = 0;j < max;j++){
                    if(ch[j] == false){
                        count++;
                        if(count == i){
                            a = j;
                        }else if(count == i+1){
                            b = j;
                            break;
                        }
                    }
                }
                if(num[a] + num[b] == 0 && num[a] < num[b]){
                    ch[a] = true; 
                    ch[b] = true;
                    sum -= 2;
                    check = 1;
                    break;
                }
            }
            if(check == 0){ ans = 0; break;}
        }
        if(ans == 1){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<stack>

using namespace std;

int main(void){
	char letter[100];
	stack<char>st;
	bool flag;
	while(1){
		fgets(letter, 100, stdin);
		if(letter[0] == '.') break;
		int i = 0;
		while(1){
			if(letter[i] == '.') break;
			if(letter[i] == '(' || letter[i] == '[')
			st.push(letter[i]);
			if(st.empty() == false){
			if(letter[i] == ')'){
				if(st.top() == '(')
				st.pop();
				else{
				cout << "no" << endl;
				flag = true;
				}
			}
			if(letter[i] == ']'){
				if(st.top() == '[')
				st.pop();
				else{
				cout << "no" << endl;
				flag = true;
				}
			}
			}
			i++;
		}
		if(st.empty() == false)
		cout << "yes" << endl;
		while(flag == true)
			st.pop();
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
 
int main()
{
    string str;
    int cursor = 0,longs;
    bool ans = true;
     
    while (1) {
        cursor = 0;
        ans = true;
        getline(cin,str);
        longs = str.length();
        if (longs == 1) {
            if (str[0] == '.') {
                break;
            }
        }
        char word[longs];
        for (int i = 0; i < longs; i++) {
            if (str[i] == '(' || str[i] == '[') {
                if (str[i] == '(') {
                    word[cursor] = '(';
                }else{
                    word[cursor] = '[';
                }
                cursor++;
            }
            if (str[i] == ')' || str[i] == ']') {
                cursor--;
                if (str[i] == ')') {
                    if (word[cursor] != '(') {
                        ans = false;
                        break;
                    }
                }else{
                    if (word[cursor] != '[') {
                        ans = false;
                        break;
                    }
                }
            }
        }
        if (ans == true && cursor == 0) {
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }
    return 0;
}

C++: #include <iostream>
#include <stack>
#include <string>
using namespace std;

int main(){
    string str;
    while(getline(cin,str)){
        if(str == ".") break;
        stack<char> st;
        char c;
        bool isok = true;
        for(int i=0;i<str.size();i++){
            c = str[i];
            if(c == '(' || c == '['){
                st.push(c);
            }else if(c == ')'){
                if(!st.empty() && st.top() == '('){
                    st.pop();
                }else{
                    isok = false;
                    break;
                }
            }else if(c == ']'){
                if(!st.empty() && st.top() == '['){
                    st.pop();
                }else{
                    isok = false;
                    break;
                }
            }
        }
        cout << (isok?"yes":"no") << endl;
    }
}

C++: #include<iostream>
#include<string>
#include<stack>
using namespace std;

int main()
{
    int a[4];
    string str;
    stack<char> s;
    
    while( getline( cin, str ) )
    {
        if( str == "." )
            break;

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

        bool j = true;
        for( int i = 0; i < str.size(); i++ )
        {
            if( str[i] == '(' )
                s.push('(');
            else if( str[i] == ')' && s.empty() == true )
            {
                j = false;
                break;
            }
            else if( str[i] == ')' && s.top() == '(' )
                s.pop();
            else if( str[i] == ')' && s.top() != '(' )
            {
                j = false;
                break;
            }
            else if( str[i] == '[' )
                s.push('[');
            else if( str[i] == ']' && s.empty() == true )
            {
                j = false;
                break;
            }
            else if( str[i] == ']' && s.top() == '[' )
                s.pop();
            else if( str[i] == ']' && s.top() != '[' )
            {
                j = false;
                break;
            }
            else;
        }
        if( j == true && s.empty() == true )
            cout << "yes" << endl;
        else
            cout << "no" << endl; 
    }
        return 0;
}