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<stack>
#include<string>

using namespace std;

int main(void){
	string str;

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

		
	}
}

C++: #include<cstdio>
#include<iostream>
#include<stack>
#include<string>
 
#define loop(lp) for(int i = 0;i < lp;i++)
 
using namespace std;       
int main(){
  string s;
  stack<char> a;
  int i=0,j=0;
  while(true){
    getline(cin,s);
    while(1){
      if(s == ".") break;
      if(s[i] == '('){
    a.push('(');  
      }else if(s[i] == ')'){
    if(a.size() == 0){
      j = 1;
      break;
    }
    if(a.top() == '('){
      a.pop();  
    }else{
      j = 1;
      break;
    }
      }else if(s[i] == '[' ){
    a.push('[');  
      }else if(s[i] == ']'){
    if(a.size() == 0){
      j = 1;
      break;
    }
    if(a.top() == '['){
      a.pop();  
    }else{
      j = 1;
      break;
    }
      }
      i++;
    }
    if(i == 0){
      break;
    }
    if(a.size() == 0 && j != 1){
    cout <<"yes"<<endl;
      }else{
    cout <<"no"<<endl;   
      }
    i = 0;
    while(a.size() != 0){
      a.pop();
    }
    j = 0;
  }
     
     
    return 0;
}

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

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

C++: #include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <functional>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long
//#define scanf scanf_s

int main()
{
	string s;
	while (getline(cin, s))
	{
		if (s[0] == '.') break;
		vector<int> v;
		v.push_back(100);
		REP(i, s.size())
		{
			if (s[i] == '(') v.push_back(0);
			if (s[i] == '[') v.push_back(1);
			if (s[i] == ')')
			{
				int n = v.back();
				v.pop_back();
				if (!(n == 0))
				{
					cout << "no" << endl;
					goto end;
				}
			}
			if (s[i] == ']')
			{
				int n = v.back();
				v.pop_back();
				if (!(n == 1))
				{
					cout << "no" << endl;
					goto end;
				}
			}
		}
		if (v.back() == 100) cout << "yes" << endl;
		else cout << "no" << endl;
	end:;
	}
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define INF 1e9

bool solve(char c1,char c2){
    if(c1=='(')return c2==')';
    else return c2==']';
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    while(1){
        string s;
        getline(cin,s);
        if(s==".")break;
        stack<char> st;
        bool ans=true;
        for(int i=0;i<s.size();i++){
            if(s[i]=='(' || s[i]=='[')st.push(s[i]);
            else if(s[i]==')' || s[i]==']'){
                if(st.empty())ans=false;
                else{
                    if(solve(st.top(),s[i])){
                        st.pop();
                    }
                    else{
                        ans=false;
                    }
                }
            }
        }
        if(!st.empty())ans=false;
        if(ans)cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
}

C++: #include <stdio.h>
#include <vector>
#include <queue>
#include <memory.h>
#include <functional>
#include <algorithm>
using namespace std;
#include <stack>

//FILE * in = freopen("input.txt", "r" , stdin);
char data[1000];


int main() {
	
	while(true) {
		bool flag = false;
		gets(data);
		if(data[0] == '.' && data[1] == 0)break;
		int i = 0;
		stack<int> a;
		while(data[i] != '.'){
			switch(data[i])
			{
			case '(':
				a.push('(');
				break;
			case '[':
				a.push('[');
				break;
			case ')':
				if(a.empty()) {
					flag = true;
					goto out;
				}
				if(a.top() == '(')
					a.pop();
				else {
					flag = true;
					goto out;
				}
				break;

			case ']':
				if(a.empty()) {
					flag = true;
					goto out;
				}
				if(a.top() == '[')
					a.pop();
				else {
					flag = true;
					goto out;
				}
				break;
			default:
				break;
			}
			i++;
		}
		out:
		if(!flag)
			puts("yes");
		else
			puts("no");
	}

	return 0;
}

C++: 
#include<iostream>
#include<stack>
main(){
 for(char i,f,c,s[101];fgets(s,101,stdin),s[0]-46;){
 std::stack<int> t;
 for(f=i=0;c=s[i++],c-46;){
  if(c==40|c==91)t.push(c);
  if(c==41|c==93){
   if(t.size()&&(c==t.top()+1||c==t.top()+2))t.pop();
   else f=1;
  }
 }
 puts(f|t.size()?"no":"yes");
}}

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

int main(){
  string str;

  while(getline(cin,str),str != "."){
    stack<char> st;
    int len = str.size();
    bool flg = false;

    for(int i = 0 ; i < len ; i++){
      if(str[i] == '(' || str[i] == '['){
	st.push(str[i]);
	continue;
      }
      if(str[i] == ')'){
	if(st.empty()){
	  flg = true;
	  break;
	}
	else if(st.top() == '(') st.pop();
	else{
	  flg = true;
	  break;
	}
      }
      else if(str[i] == ']'){
	if(st.empty()){
	  flg = true;
	  break;
	}
	else if(st.top() == '[') st.pop();
	else{
	  flg = true;
	  break;
	}
      }
    }

    if(!flg&&st.empty()) cout << "yes" << endl;
    else cout << "no" << endl;
  }

  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

long long int A[200001] = {0};
long long int sum[300000] = {0};

int main(){

  string s;

  getline(cin , s);

  while(s[0] != '.'){
    string ans = "yes";

    stack<char> ST;
    for(int i = 0; i < (int)s.size(); i++){
      if(s[i] == '(' or s[i] == '[')ST.push(s[i]);
      else if(s[i] == ')'){
        if(!(ST.empty()) and ST.top() == '(')ST.pop();
        else ans = "no";
      }else if(s[i] == ']'){
        if(!(ST.empty()) and ST.top() == '[')ST.pop();
        else ans = "no";
      }
    }
    if(!(ST.empty()))ans = "no";

    cout <<ans<<endl;
    getline(cin , s);
  }

  return 0;
}