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 <bits/stdc++.h>
using namespace std;

typedef long long ll;


char str[104];

int main(){
    while(1){
        stack<int> st;
        bool judge = true;

        for(int i=0;i<100;i++){
            cin.get(str[i]) ;
            if(str[i-1]=='.') break;
        }
        if(str[0]=='.')break;
    
        int i=0;
        while(str[i] != '.'){
            if(str[i]=='(' || str[i]=='['){
                st.push(str[i]);
            }else if(!st.empty()){
                if(str[i]==')'){
                    if(st.top() == '('){
                        st.pop();
                    }else{
                        judge = false;
                    }
                }else if(str[i]==']'){
                    if(st.top() == '['){
                        st.pop();
                    }else{
                        judge = false;
                    }
                }
            }else if(st.empty()){
                if(str[i]==')' || str[i]==']') judge = false;
            }
            if(judge==false){
                break;
            }
            i++;
        }
        if(!st.empty()){
            judge = false;
        }
        if(judge){
            printf("yes\n");
        }else{
            printf("no\n");
        }
    }

}

C++: #include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>

using namespace std;

int search(int i, char c);

char str[200];
int l;

int main()
{
	while(1){
		fgets(str, sizeof(str), stdin);
		if(str[0] == '.') break;
		int ans = 1;
		l = strlen(str);
		for(int i = 0; i < l; i++){
			if(str[i] == '(' || str[i] == '['){
				ans = search(i, str[i]);
				if(ans == 0) break;
			} else if(str[i] == ')' || str[i] == ']'){
				ans = 0;
				break;
			}
		}
		if(ans == 1) cout << "yes" << endl;
		else if(ans == 0) cout << "no"<< endl;
	}
	return 0;
}

int search(int i, char c)
{
	if(i == l-1) return 0;
	if(c == '('){
		for(int j = i+1; j<l; j++){
			if(str[j] == ')'){
				str[j] = '0';
				return 1;
			}
		}
	} else if(c == '['){
		for(int j = i+1; j<l; j++){
			if(str[j] == ']'){
				str[j] = '0';
				return 1;
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

void solve(string s) {
    int st = 0, ed = s.size() - 2;
    while (true) {
        if (st >= ed) {
            cout << "yes" << endl;
            return;
        }
        if (s[st] == '(') {
            while (true) {
                if (s[ed] == ')') break;
                ed--;
                if (st >= ed) {
                    cout << "no" << endl;
                    return;
                }
            }
        } else if (s[st] == '[') {
            while (true) {
                if (s[ed] == ']') break;
                ed--;
                if (st >= ed) {
                    cout << "no" << endl;
                    return;
                }
            }
        }
        st++;
    }
    return;
}

signed main(void) {
    int n, p, m, w, h;
    string s;
    int a, b, c, d;
    while (getline(cin, s)) {
        if (s == ".") return 0;
        solve(s);
        //return 0;
    }
}

C++: #include<iostream>
#include<string>
#include<string.h>

using namespace std;


int main()
{
	string str,str2;
	
	cin >> str;

	while(true)
	{
		string tmp;
		cin >> tmp;
		str += tmp;
		if(tmp[tmp.length()-1] == '.')break;
	}


	while(cin >> str2)
	{
		while(true)
		{
			string tmp;
			cin >> tmp;
			str2 += tmp;
			if(tmp[tmp.length()-1] == '.')break;
		}


		int f = 0;//( 1 [ 2
		bool judg = false;

		int tmp[2] = {0,0};
		int i = 0;
		for(i = 0;i < str.length();i++)
		{
			char c = str[i];

			if(f == 0){
				if(c == ')' && !tmp[0])break;
				if(c == ']' && !tmp[1])break;}

			if(f == 1)
			{	
				if(c == ']')break;
				if(c == ')')f = 0;
			}
			if(f == 2)
			{
				if(c == ')')break;
				if(c == ']')f = 0;
			}


			if(c == '('){
				f = 1;tmp[0]++;}
			if(c == '['){
				f = 2;tmp[1]++;}

			if(c == ')'){
				tmp[0]--;}
			if(c == ']'){
				tmp[1]--;}
		}
		if(i == str.length())judg = true;

		if(judg)cout << "yes" << endl;
		else	cout << "no" << endl;

		str = str2;
	}

	return 0;
}

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

int main()
{
	string str;
	while(getline(cin,str), str!=".")
	{
		bool ok=true;
		stack<char> s;
		for(int i=0; i<str.size(); i++)
		{
			if(str[i]=='(' || str[i]=='[')
			{
				s.push(str[i]);
			}
			else if(str[i]==')')
			{
				if(s.empty())    { ok=false; break; }
				if(s.top()!='(') { ok=false; break; }
				s.pop();
			}
			else if(str[i]==']')
			{
				if(s.empty())    { ok=false; break; }
				if(s.top()!='[') { ok=false; break; }
				s.pop();
			}
			else if(str[i]=='.')
			{
				break;
			}
		}

		if(!s.empty()) { ok=false; }

		cout << (ok?"yes":"no") << endl;
	}
}