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++: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P) 
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }



int n;
string str;

int main() {
    while (cin >> n) {
        for (int it = 0; it < n; ++it) {
            int out = 0, rui[5] = {0};
            while (out < 3) {
                cin >> str;
                if (str == "HIT") {
                    if (rui[3] == 1) rui[4] += 1, rui[3] = 0;
                    if (rui[2] == 1) rui[3] += 1, rui[2] = 0;
                    if (rui[1] == 1) rui[2] += 1; rui[1] = 0;
                    rui[1] += 1;
                }
                if (str == "OUT") ++out;
                if (str == "HOMERUN") {
                    rui[4] += rui[1] + rui[2] + rui[3] + 1, rui[1] = rui[2] = rui[3] = 0;
                }
            }
            cout << rui[4] << endl;
        }
    }
    return 0;
}

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

class Baseball{
private:
    int m_runner = 0;
    int m_out = 0;
    int m_point = 0;

public:
    void isHit(){
        if(m_runner < 3){
            ++m_runner;
        //if fill all base    
        } else {
            ++m_point;
        }
    }
    void isHomerun(){
        //add point and reset runner
        m_point += m_runner + 1;
        m_runner = 0;
    }
    void setOut(){
        ++m_out;
    }
    int getOut(){
        return m_out;
    }
    int getPoint(){
        return m_point;
    }

    void resetInning(){
        m_runner = 0;
        m_out = 0;
        m_point = 0;
    }
};

int main(){
    int n;
    std::string event;

    std::cin >> n;
    Baseball baseball;
    for(int i = 0; i < n; ++i){
        //until out count = 3
        while(baseball.getOut() < 3) {
            //input event
            std::cin >> event;
            if (event == "HIT") {
                baseball.isHit();
            } else if (event == "OUT") {
                baseball.setOut();
            } else if (event == "HOMERUN"){
                baseball.isHomerun();
            }
        }
        std::cout << baseball.getPoint() << std::endl;
        resetInning();
    }
}

C++: #include <string>
#include <iostream>
using namespace std;
int N, c1, c2, c3, out, ret; string S;
int main() {
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		c1 = 0, c2 = 0, c3 = 0, out = 0, ret = 0;
		while (out != 3) {
			cin >> S;
			if (S == "HIT") {
				ret += c3, c3 = c2, c2 = c1, c1 = 1;
			}
			else if (S == "HOMERUN") {
				ret += c1 + c2 + c3;
			}
			else {
				out++;
			}
		}
		printf("%d\n", ret);
	}
	return 0;
}

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

void countHR();
void move(string str);

int mask = (1 << 4) - 1, pointMask = (1 << 4), now = 1, outCnt = 0, cnt = 0;

int main(){
    int n;
    cin >>n;
    for(int i = 0; i < n; i++){
        now = 1; outCnt = 0; cnt = 0;
        while(outCnt < 3){
            string str;
            cin >>str;
            move(str);
        }
        cout <<cnt <<endl;
    }
    return 0;
}

void move(string str){
    if(str == "HIT"){
        now = (now << 1) + 1;
        if((now & pointMask) != 0){
            cnt++;
            now = (now & mask);
        }
    } else if(str == "HOMERUN"){
        countHR();
    } else if(str == "OUT"){
        outCnt++;
    }
}

void countHR(){
    for(int countMask = 1; countMask < 16; countMask = (countMask << 1)){
        if((now & countMask) != 0){
            cnt++;
        }
    }
    now = 1;
}

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

int main(){
  int n;
  scanf("%d\n", &n);
  while(n--){
    int runner=0, out=0, score=0;
    while(true){
      string s;
      cin>>s;
      if(s=="HIT"){
        if(runner==3)score++;
        else runner++;
      }
      else if(s=="HOMERUN"){
        score+=(runner+1);
        runner=0;
      }
      else if(s=="OUT"){
        out++;
        if(out==3)break;
      }
    }
    cout<<score<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define COUNT(i, n) for(int i = 1; i <= n; i ++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))
 
using namespace std; 

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;
const int H = 4;

int main(void){
    int n; cin >> n;

    while(n --){
        int out = 0;
        vi t(5);
        while(out != 3){
            t[0] = 1;
            string in; cin >> in;
            
            if(in == "OUT")
                out ++;
            else
                rep(i, 4){
                    int next = in == "HIT" ? 4 - i:H;
                    if(t[3 - i]) t[next] ++, t[3 - i] = 0;
                }
        }
        cout << t[H] << endl;
    }
 
    return 0;
}

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

int main(){
  int n,ansc=0,o=0,hr=0,h=0,o2=0;
  string event;
  cin>>n;
  int i=0;

  while(1){
    cin>>event;
    if(event=="OUT"){
      o++;
      o2++;
    }
    if(event=="HIT")h++;
    if(event=="HOMERUN")hr++;
    if(o2==3*n)break;

    if(h==4){
      ansc++;
      h--;
    }
    else if(o==3){
      o=0;
      h=0;
      hr=0;
    }
    else if(hr==1){
      ansc+=h+1;
      h=0;
      hr=0;
    }
  
  i++;
}
  cout<<ansc<<endl;
return 0;
}