Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	n, _ := strconv.Atoi(stdin.Text())
	for i := 0; i < n; i++ {
		base := [3]bool{}
		score, out := 0, 0
		for stdin.Scan() {
			switch stdin.Text() {
			case "HIT":
				if base[2] { // 3塁
					score++
				}
				if base[1] { // 2塁
					base[2] = true
					base[1] = false
				}
				if base[0] { // 1塁
					base[1] = true
				}
				base[0] = true
			case "HOMERUN":
				for i := 0; i < 3; i++ {
					if base[i] {
						score++
						base[i] = false
					}
				}
				score++
			case "OUT":
				out++
			}
			if out >= 3 {
				fmt.Println(score)
				break
			}
		}
	}
}

C++: 
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <bitset>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
#define strtok_r strtok_s
#endif

#define ITER(c)             __typeof__((c).begin())
#define FOREACH(it, c)      for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c)            __typeof__((c).rbegin())
#define RFOREACH(it, c)     for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n)           REPEAT(i, 0, n)
#define RREP(i, n)          RREPEAT(i, 0, n)
#define REPEAT(i, k, n)     for(int i = (k); i < (k+n); ++i)
#define RREPEAT(i, k, n)    for(int i = (k)+(n)-1; i >= (k); --i)
#define FROMTO(i,f,t)       for(int i = f; i < t; i++)
#define ALL(c)              (c).begin(), (c).end()
#define LLPOW(p1,p2)        ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A)          (sizeof(A)/sizeof((A)[0]))
#define CIN_NO_SYNC         do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)
#define GETSTR(p)           fgets((p), sizeof(p), stdin)
#define CHOMP(p)            do{ char *_q = (p) + strlen(p)-1; if(*_q == '\n' || *_q == '\r') *_q = 0; } while(0)
#define FILL(m,v)           memset(m, v, sizeof(m))
#define mp                  make_pair
#define pb                  push_back
template<class _T> _T MAX(_T p1,_T p2){return (p1>p2)?p1:p2;} 
template<class _T> _T MIN(_T p1,_T p2){return (p1<p2)?p1:p2;} 

typedef long long ll;
typedef unsigned long long ull;

#define X real()
#define Y imag()
typedef double D;
typedef complex<D> P;
#define EPS (1e-9)

#ifdef _DEBUG
template<class _T>
inline void _prfe(const char *_n, _T _c, bool _p = false){
    ITER(_c) _it=_c.begin();
    if(_p){ cout<<_n<<" = ["<<endl;for(;_it!=_c.end();++_it)cout<<"    "<<*_it<<endl;cout<<"]"<<endl; }
    else{ cout<<_n<<" = [ "<<*_it++;for(;_it!=_c.end();++_it)cout<<", "<<*_it;cout<<" ]"<<endl; }
}
#define pf printf
#define pr(n) do{cout<<#n" = "<<(n)<<endl;}while(0)
#define prfe(n) _prfe(#n, n)
#define prfep(n) _prfe(#n, n, true)
#define dbgchk(n) do{if(n)throw;}while(0)
#else
#define pf(...) /* */
#define pr(...) /* */
#define prfe(...) /* */
#define prfep(...) /* */
#define dbgchk(...) /* */
#endif

int main(){
    int n;
    cin >> n;
    REP(i,n){
        int k = 0, o = 0, p = 0;
        while(1){
            string s;
            cin >> s;
            if(s == "HIT"){
                k = (k << 1) | 1;
                if(k&(1<<3)) p++;
                k &= 7;
            }
            if(s == "HOMERUN"){
                while(k){
                    if(k&1) p++;
                    k >>= 1;
                }
                p++;
            }
            if(s == "OUT"){
                o++;
                if(o == 3) break;
            }
        }
        cout << p << endl;
    }
    return 0;
}

C++: #include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
using namespace std;

int loop;
int HIT,OUT,point;
string stait;
int main(){
  scanf("%d",&loop);
  for(int i=0;i<loop;i++){
    int base[4]={0};
    point = 0;
    OUT=0;
      while(OUT<3){
	cin>>stait;
	cout<<stait[1];
	if(stait[1]=="O"){
	  for(int j=1;j<4;j++)
	    if(base[j]==1){base[j]=0;point++;}
	  point++;
	}
	if(stait[1]=="U"){OUT++;}
	if(stait[1]=="I"){
	  if(base[3]==1){
	    point++;
	  }
	  for(int j=3;j>1;j--){
	    base[j]=base[j-1];
	    base[j-1]=0;
	  }
	}
      }
      printf("%d\n",point);
  }
}

C++: #include <iostream>
#include <string>
#include <queue>
 
class Baseball{
	int score, out_count;
	std::queue<bool> runners;
public:
	Baseball() : score(), out_count(){}
	void hit();
	void homerun();
	void out();
	int get_score() {return score;}
	int get_out() {return out_count;}
};

void Baseball::hit(){
	runners.push(true);
	if(runners.size() == 4){
		++score;
		runners.pop();
	}
}

void Baseball::homerun(){
	score += runners.size() + 1;
	while(!runners.empty()){
		runners.pop();
	}
}

void Baseball::out(){
	++out_count;
}

int main(){
	int inning;
	std::cin >> inning;
	//inningの回数だけループ
	for(int i = 0; i < inning; ++i){
		Baseball game;
		while(game.get_out() != 3){
			std::string event;
			std::cin >> event;
			if(event == "HIT"){
				game.hit();
			}
			else if(event == "HOMERUN"){
				game.homerun();
			}
			else if(event == "OUT"){
				game.out();
			}
		}
		std::cout << game.get_score() << std::endl;
	}
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
	const string event[] = { "HIT", "OUT", "HOMERUN" };
//	cut here before submit 
//	freopen("testcase.baseball2", "r", stdin);
	string str = "";
	int n;

	getline (cin, str );
	stringstream ssn(str);
	ssn >> n;
	queue <char> stat;

	int score = 0;
	int out = 0;
	int count = 0;
	int i;
	while (getline (cin, str ) ){
		
		for (i = 0; i < sizeof(event)/sizeof(event[0]); ++i){
			if (str == event[i]){
				switch(i){
					case 0:
						stat.push ('R');
						break;
					case 1:
						++out;
						break;
					case 2:
						int runner = 0;
						while (!stat.empty() ){
							char c = stat.front();
							if (c == 'R'){
								++runner;
							} // end if
							stat.pop();
						} // end while
						score += runner + 1;
						break;
				} // end switch
				break;
			} // end if
		} // end for
		if (out == 3){
			cout << score << endl;
			score = 0;
			out = 0;
			while (!stat.empty() ){
				stat.pop();
			} // end while
			++count;
		} // end if
		if (stat.size() == 4){
			if (stat.front() == 'R'){
				++score;
			} // end if
			stat.pop();
		} // end if
		if (count == n){
			break;
		} // end if
	} // end loop

//	cout << res << endl;	
		
	return 0;
}

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

int main(){
    int hit, out, score, data_set_num;
    std::string event;
    std::cin >> data_set_num;


    while(data_set_num--){
        std::cin >> event;
        if(event == "HIT"){
            ++hit;
            if(hit == 4){
                ++score;
                hit = 3;
            }
        }else if(event == "HOMERUN"){
            score += (hit + 1);
            hit = 0;
        }else if(event == "OUT"){
            ++out;
        }

        if(out == 3){
            std::cout << score << std::endl;
            hit = 0;
            score = 0;
        }
    }

    return 0;
}