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;

#define rep(i, n) for (int i = 0; i < (n); i++)


int main() {
	string s;
	while (cin >> s) {
		using P = pair<char, int>;
		queue<P> que;
		que.emplace('a', -1);
		bool ok = true;
		for (char c : s) {
			if (c == '('){ if(que.front().first == '(') que.front().second++; else que.emplace('(', 1); }
			if (c == ')'){ if(que.front().first == ')') que.front().second--; else ok = false; }
			if (c == '{'){ if(que.front().first == '{') que.front().second++; else que.emplace('{', 1); }
			if (c == '}'){ if(que.front().first == ')') que.front().second--; else ok = false; }
			if (que.front().second == 0) que.pop();
		}
		cout << (ok && que.size() == 1 ? "yes" : "no");
	}
}

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

#define MAX_STR_LEN 102

int CheckBracket(char *bracketStr, int *bracketStrIdx, char inputStr);

int main()
{
	char inputStr[MAX_STR_LEN]   = {'\0'};		// Array for input string
	int  inputStrLen = 0;						// Length of input string
	char bracketStr[MAX_STR_LEN] = {'\0'};		// Array for keep left-bracket
	int  bracketStrIdx = 0;						// Index of "bracketStr"
	char compareBracket = '\0';					// Valiable of select bracket to compare
	int  falseFlg = 0;							// Flag of sign false
	int  i = 0;									// Loop valiable
	
	do{
		// Initialize parameter.
		for(i = 0; i < MAX_STR_LEN; i++)
		{
			inputStr[i]    = '\0';
			bracketStr[i]  = '\0';
		}
		bracketStrIdx  = 0;
		compareBracket = '\0';
		falseFlg       = 0;
		
		// Input string.
//		printf("Input string >> ");
		fgets(inputStr, MAX_STR_LEN, stdin);
//		puts(inputStr);
		inputStrLen = strlen(inputStr);
		
		// If input string is '.' only, end.
		if('.' == inputStr[0])
		{
			break;
		}
		
		// Check to match bracket.
		for(i = 0; i < inputStrLen; i++)
		{
			switch(inputStr[i])
			{
			// If inputStr[i] is left-bracket, connect to "bracketStr".
			case '(':
			case '[':
				bracketStr[bracketStrIdx] = inputStr[i];
				bracketStrIdx++;
				break;
				
			// If inputStr[i] is right-bracket, Check to match bracket.
			case ')':
			case ']':
				falseFlg = CheckBracket(bracketStr, &bracketStrIdx, inputStr[i]);
				break;
				
			case '.':
				// If bracketStr is not empty, falseFlg is 1.
				if(0 != bracketStrIdx)
				{
					falseFlg = 1;
				}
				break;
			default:
				break;
			}
			
			if(1 == falseFlg)
			{
				break;
			}
		}
		
		// Disp result.
		if(0 == falseFlg)
		{
			printf("yes\n");
		}
		else
		{
			printf("no\n");
		}
	}while(1);
	
	return 0;
}

// CheckBracket
// Function  : Check to match bracket.
// Param[in] : char *bracketStr, int *bracketStrIdx, char inputStr
// Param[out]: 0(true) or 1(false)
// Global    : 
int CheckBracket(char *bracketStr, int *bracketStrIdx, char inputStr)
{
	char compareBracket = '\0';
	
	// If left-bracket is empty, falseFlg is 1.
	if(0 == *bracketStrIdx)
	{
		return 1;
	}
	
	// Select the compare bracket.
	if(')' == inputStr)
	{
		compareBracket = '(';
	}
	else
	{
		compareBracket = '[';
	}
	
	// Check to match bracket.
	if(compareBracket == bracketStr[(*bracketStrIdx) - 1])
	{
		bracketStr[(*bracketStrIdx) - 1] = '\0';
		(*bracketStrIdx)--;
	}
	else
	{
		return 1;
	}
	
	return 0;
}

C++: #include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<stack>
#include<queue>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;


using namespace std;



int main()
{

  while(true){
    string text;
    getline(cin,text);

    if(text=="."){
      break;
    }

    stack<char> kakko;
    bool flag=true;

    for(int i=0;i<text.length();i++){
      
      //cout << text[i] << endl;
      
      if(text[i]=='('||text[i]=='['){
        kakko.push(text[i]);
      }


      if(text[i]==')'||text[i]==']'){
       if(kakko.empty()){
          flag = false;
          break; 
        }else if((kakko.top()=='(' && text[i]==']')||((kakko.top()=='[' && text[i]==')'))){
          flag = false;
          break;
        }else{
          kakko.pop();
        }
      }

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

  }

  return 0;
}

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

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






int main(){
  string s;
  while(getline(cin,s)){
    if(s=="."){break;}
  int k=0,m=0;
  int count=0;
  stack<int>  a;
  a.push(0);
  bool j=true;
  for(int i=0;i<s.size();i++){
    if(s[i]=='('){k++; a.push(1);}
    if(s[i]==')'){k--; if(a.top()!=1){j=false; break;} a.pop();}
    if(s[i]=='['){m++; a.push(2);}
    if(s[i]==']'){m--; if(a.top()!=2){j=false; break;} a.pop();}
  }
  if(k!=0 || m!=0){j=false;}
  if(j){cout<<"yes"<<endl;}
  else{cout<<"no"<<endl;}
  
  }
  
  return 0;
}

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

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