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 <vector>
using namespace std;

int main(){
    string s;
    getline(cin, s);

    for(int i=0; i<(int)s.length(); i++){
        if('A' <= s[i] && s[i] <= 'Z'){
            s[i] = 'a' +s[i]-'A';
        }else if('a' <= s[i] && s[i] <= 'z'){
            s[i] = 'A' +s[i]-'a';
        }
    }
    cout << s << endl;
    return 0;
}

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

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

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

bool checkAndPop(stack<char>& stk, char c) {
  if (stk.empty()) return false; 
  if ( (c == ')') && (stk.top() != '(') ) return false;
  if ( (c == ']') && (stk.top() != '[') ) return false;

  stk.pop();
  return true;
}

bool solve(const std::string& s) {
  stack<char> stk;
  for (auto c : s) {
    switch (c) {
    case '(':
    case '[':
      stk.push(c);
      break;
      
    case ')':
    case ']':
      if (!checkAndPop(stk, c)) return false;
      break;
    }
  }
  return stk.empty();
}

int main() {
  string s;
  while(getline(cin, s), s.size() > 1) {
    if (solve(s)) cout << "yes" << endl;
    else          cout << "no"  << endl;
  }
  return 0;
}

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

int main(){
  char str[100];
 
  while ( 1 ){
    string s = "yes";
    cin.getline( str, sizeof( str ) );
    if ( str[0] == '.' ) break;
    stack<char> sta;
    for ( int i = 0; str[i] != '\0'; i++ ){
      if ( str[i] == '(' || str[i] == '[' ){
        sta.push( str[i] );
      }else if ( str[i] == ')' ){
        if ( sta.empty() ){
        	s = "no";
        	break;
        }
        if ( sta.top() == '(' ){
          sta.pop();
		}else{
	  		s = "no";
	  		break;
		}
      }else if ( str[i] == ']' ){
        if ( sta.empty() ){
        	s = "no";
        	break;
        }
        if ( sta.top() == '[' ){
          sta.pop();
        }else{
	  		s = "no";
	  		break;
		}
      }
    }
    if ( !sta.empty() ) s = "no";
      cout << s << endl;
  }
}

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

typedef ostringstream OSS; typedef istringstream ISS;
typedef long long LL;
typedef pair<int, int> PII;  typedef pair<LL, LL> PLL;
typedef vector<int>    VI;   typedef vector<VI>   VVI;   typedef vector<VVI>   VVVI;
typedef vector<LL>     VLL;  typedef vector<VLL>  VVLL;  typedef vector<VVLL>  VVVLL;
typedef vector<double> VD;   typedef vector<VD>   VVD;   typedef vector<VVD>   VVVD;
typedef vector<string> VS;   typedef vector<VS>   VVS;   typedef vector<VVS>   VVVS;
typedef vector<bool>   VB;   typedef vector<VB>   VVB;   typedef vector<VVB>   VVVB;
typedef vector<PII>    VPII; typedef vector<VPII> VVPII; typedef vector<VVPII> VVVPII;
typedef vector<PLL>    VPLL; typedef vector<VPLL> VVPLL; typedef vector<VVPLL> VVVPLL;

typedef unsigned int  UI;
typedef vector<UI>    VUI;
typedef vector<VUI>   VVUI;

#define fst first
#define snd second
// #define Y first
// #define X second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x)  (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define RANGEBOX(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define RANGE(x, l, r) ((l) <= (x) && (x) <= (r))
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define rrep(i, N) for (int i = N - 1; i >= 0; i--)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define RREP(i, N, last) for (int i = (init - 1); i >= last; i--)
#define MAXUD(orig, target) orig = max(orig, target)
#define MINUD(orig, target) orig = min(orig, target)
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a)   { OSS oss; oss << a; return oss.str(); };

template<typename T=int> inline void dump(vector<T> vs, bool ent=false) { rep(i, vs.size()) cout << vs[i] << (i+1==vs.size() ? '\n' : ' '); if (ent) cout << endl; }
template<typename T = int> inline void dump(vector<vector<T>> vs, bool ent = false) { rep(i, vs.size()) dump<T>(vs[i]); if (ent) cout << endl; }

const int    INF  = 0x3f3f3f3f;
const LL     INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;
const int    DX[] = {1,  0, -1, 0};
const int    DY[] = {0, -1,  0, 1};
const double EPS  = 1e-12;
// const double PI   = acos(-1.0);
// lambda: [](T1 x)->T2{return y;}
// simple lambda: [](T x){return x;}

bool solve(string s) {
    stack<char> stk;

    for (auto c : s) {
        if (c == '[' || c == '(') {
            stk.push(c);
        } else if (c == ']' || c == ')') {
            if (!stk.size()) return false;

            string t = string() + stk.top() + c;
            stk.pop();

            if (t != "()" && t != "[]") {
                return false;
            }
        }
    }

    return stk.size() == 0;
}

int main(void) {
    string s;
    while (getline(cin, s), s != ".") {
        cout << (solve(s) ? "yes" : "no") << endl;
    }

    return 0;
}

C++: #include <stdio.h>



int main(void){
  char c, moji[101];
  int maru, kaku;
  bool end = false;
  while(1){ 
    if(end){
      maru = 0;
      kaku = 0;
    }
    end = false;
    for(int i=0; i<101; i++){
      scanf("%c", &c);
      if(c == '\n'){
	moji[i] = '\0';
	break;
      }else{
	moji[i] = c;
      }
    }
    if(moji[0] == '.'){
      break;
    }
    for(int i=0; i<101; i++){
      if(moji[i] == '.'){
	end = true;
	break;
      }else if(moji[i] == '('){
	maru++;
      }else if(moji[i] == ')'){
	maru--;
	if(maru<0){
	  break;
	}
      }else if(moji[i] == '['){
	kaku++;
      }else if(moji[i] == ']'){
	kaku--;
	if(kaku<0){
	  break;
	}
      }else if(moji[i] == '\0'){
	break;
      }
    }
    if(end){
      if(maru == 0 && kaku == 0){
	printf("yes\n");
      }else{
	printf("no\n");
      }
    }
  }
  return 0;
}