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 <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
#define ll long long
#define pb push_back

int main()
{
    // cinだとスペース取れない
    // scanfだと変数をうまく用意しないと死ぬ
    // 一文字目スペースだと死ぬ
    string n = "";
    vector<string> x;
    bool flag;
    int k = 0;
    while (1)
    {
        char line[512];
        cin.getline(line, sizeof(line)); //スペースを含む入力を、ちぎらず受け付ける
                                         // cout << "input : " << line << endl;
        for (int i = 0; i < 256; i++)
        {
            if (line[i] == ' ')
            {
                line[i] = '0';
            }
        }
        n = line;
        if (n.at(0) == '.')
            break;
        vector<char> a;
        for (int i = 0; i < n.size(); i++)
        {
            char c = line[i];
            if (c == '(' || c == ')' || c == '[' || c == ']')
            {
                a.push_back(c);
            }
         }
        // for (auto i : a)
        // {
        //     cout << i << " ";
        // }
        flag = (a.size() + 1) % 2; // 1 == true
        int zerocnt = 0;
        if (flag && a.size() > 0)
        {
            for (int i = 0; i < a.size() - 1; i++)
            {
                if (a[i] != '0')
                {
                    for (int j = i + 1; j < a.size(); j++)
                    {
                        if ((a[i] == '(' && a[j] == ')') || (a[i] == '[' && a[j] == ']'))
                        {
                            a[i] = '0';
                            a[j] = '0';
                            zerocnt += 2;
                            if (zerocnt == a.size())
                                break;
                            j = a.size() - 1;
                            i = -1;
                        }
                        else if (a[j] == '0')
                        {
                            continue;
                        }
                        else
                        {
                            j = a.size() - 1;
                        }
                    }
                }
            }
        }
        // ここも変更
        if (flag && zerocnt == a.size())
        {
            x.push_back("yes");
        }
        else
        {
            x.push_back("no");
        }
        k++;
    }
    for (int i = 0; i < x.size(); i++)
    {
        cout << x[i] << endl;
    }
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
int main(){

  while(1){
	char hoge[200];
	int i = 0;

	//	getline(cin, hoge);

	while(1){
	  hoge[i] = getchar();
	  //	  scanf("%c",&hoge[i]);
	  if(hoge[i]=='\n') continue;
	  if(hoge[i]=='.') break;
	  i++;
	}
	if(hoge[0]=='.') break;

	int mini = 0;
	int big = 0;
	bool now[200] = {};
	int b=0;
 //????????§??????????????????

	REP(a,i){
	  if(hoge[a]=='('){
		mini++;
		b++;
		now[b] = false;
	  }else if(hoge[a]==')'){
		if(now[b] == false) {
		  mini--;
		  b--;
		}else break;
	  }else if(hoge[a]=='['){
		big++;
		b++;
		now[b] = true;
	  }else if(hoge[a]==']'){
		if(now[b] == true){
		  big--;
		  b--;
		}else break;
	  }
	  if(mini < 0||big < 0) break;
	}

	if(mini==0&&big==0) cout << "yes" << endl;
	else cout << "no" << endl;
  }
}

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

int main(){
	string S;
	int n=0;
	stack<int> T[92000];
	bool hantei=true;

	while (true){
		getline(cin,S);
		hantei=true;
		if(S=="."){
			break;
		}
		for(int i=0;i<S.size();i++){
			if(S[i]=='(' || S[i]=='['){
				T[n].push(S[i]);
			}
			if(S[i]==')' || S[i]==']'){
				if(T[n].empty()){
					hantei=false;
				}
				else{
					if((T[n].top()=='(' && S[i]==']')|| (T[n].top()=='[' && S[i]==')')){
						hantei=false;
					}
					T[n].pop();
				}
			}
		}
		if(T[n].empty()==false){
			hantei=false;
		}
		cout<<(hantei?"yes":"no")<<endl;
		n++;
	}
	return 0;
}

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

int main(void){
	char str[101];
	
	while(1){
		//入力
		fgets(str,101,stdin);
		if(str[0]=='.')break;

		//計算
		stack<int> s;
		s.push(0);
		int flag=1;
		for(int i=0; str[i]!='.'; i++){
			if		(str[i]=='('){
				s.push(1);
			}else if(str[i]=='['){
				s.push(2);
			}else if(str[i]==')'){
				if(s.top()!=1){flag=0; break;}
				s.pop();
			}else if(str[i]==']'){
				if(s.top()!=2){flag=0; break;}
				s.pop();
			}
		}
		if(s.top()!=0){
			flag=0;
		}

		//出力
		if(flag)
			cout << "yes" << endl;
		else
			cout << "no" << endl;
	}
	
	return 0;
}

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

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

        if (flag) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }

    return 0;
}

C++: #include <iostream>
#include <cstring>
#include <stack>

using namespace std;

int main() {

  string str;
  while(getline(cin,str) && !(str.length()==1 && str[0]=='.')) {
    //cout<<str<<endl;
    stack<char> checker;
    bool flag = true;

    for(int i=0; i<str.length() && flag==true; i++) {
      if(str[i] == '(' || str[i] == '[') {
	checker.push(str[i]);
      }
      else if(str[i] == ')') {
	if(checker.empty()) {
	  flag = false;
	}
	else if(checker.top() != '(') {
	  flag = false;
	}
	else {
	  checker.pop();
	}
      }
      else if(str[i] == ']') {
	if(checker.empty()) {
	  flag = false;
	}
	else if(checker.top() != '[') {
	  flag = false;
	}
	else {
	  checker.pop();
	}
      }
    }

    if(flag==true && checker.empty()) {
      cout<<"yes"<<endl;
    }
    else {
      cout<<"no"<<endl;
    }
  }

}