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
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef map<int, int> MAPII;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;

#define MP make_pair
#define fastIO	cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//for gcc (未test)
// #define FOREACH_IT(it,c)	for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(), c_end=c.end(); it!=c_end; ++it)

// ------------------- include, typedef, define END. -------------------

int Hit(int *rui){
	rui[0]++;
	// 塁を進める
	FOR(i, 1, 4){
		if (rui[i - 1]==2){
			rui[i]++;
			rui[i - 1] = 1;
		}
	}
	if (rui[3]!=0){
		rui[3] = 0;
		return 1;
	}
	return 0;
}

int Homerun(int *rui){
	int ret = 1;
	FOR(i, 0, 4)
		if (rui[i])
			ret++;
	return ret;
}

int main(){
	fastIO;
	int n, outCount = 0, tokuten = 0;
	string in;
	// rui[0]〜rui[2] = 1塁〜3塁, rui[3] = 本塁
	// 各値はその塁にいる人数(0〜2)
	int rui[4] = {};
	cin >> n;
	while (cin >> in){
		if (in == "OUT")
			outCount++;
		if (outCount < 3){
			if (in == "HIT"){
				tokuten += Hit(rui);
			}
			else if (in == "HOMERUN"){
				tokuten += Homerun(rui);
				FOR(i, 0, 4)	rui[i] = 0;
			}
		}
		else{
			cout << tokuten << endl;
			FOR(i, 0, 4)	rui[i] = 0;
			tokuten = 0;
			outCount = 0;
		}
	}
	return 0;
}

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

int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    vector<int> base(3,0);
    int res=0;
    int out=0;
    while(out!=3){
      string s;
      cin>>s;
      if(s=="HIT"){
	res+=base[2];
	base[2]=base[1];
	base[1]=base[0];
	base[0]=1;
      }
      if(s=="OUT"){
	out++;
      }
      if(s=="HOMERUN"){
	res+=base[0]+base[1]+base[2]+1;
	for(int i=0;i<3;i++) base[i]=0;
      }

    }
    cout<<res<<endl;

  }
  return 0;
}

C++: #define _USE_MATH_DEFINES
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<list>
#include<stack>
#include<queue>
#include<cctype>
#include<iomanip>
#include<functional>
#include<numeric>
#include<map>
#include<set>
#include<complex>
#define EPS 1e-10
using namespace std;
typedef long long llong;
int main() {
	int n;
	cin >> n;
	string s;
	for (int i = 0; i < n; i++) {
		vector<int>base(4,0);
		int out = 0, score = 0;
		while (out!=3) {
			cin >> s;
			if (s == "OUT")out++;
			else if (s == "HIT") {
				for (int j = 3; 0 < j; j--) {
					base[j] = base[j - 1];
				}
				base[0] = 1;
				if (base[3] == 1) {
					base[3] = 0;
					score++;
				}
			}
			else if (s == "HOMERUN") {
				int cnt = 0;
				for (int j = 0; j < 3; j++) {
					if (base[j] == 1) {
						cnt++;
						base[j] = 0;
					}
				}
				score += 1 + cnt;
			}
		}
		cout << score << endl;
	}
	return 0;
}

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

class Baseball{

private:
	int point;
	int out;
	int base;   //0:no runner 1:runner
				//home,third,second,first

public:
	
	//constructor
	Baseball(int fir_point, int fir_out, int fir_base){
		point = fir_point;
		out = fir_out;
		base = fir_base;
	}

	//get point
	int get_point(){
		return point;
	}
	
	//get out count
	int get_out(){
		return out;
	}

	//hit
	void hit(){
		base = (base * 10) + 1;
		
		if(base >= 1000){ //home,third,second,first
			base -= 1000; 
			point += 1;	  //get one point
		}
	}
    
	//home run
	void home_run(){
		point += 1;  //batter point
		for(int i = base; i > 0; i /= 10){
			point += i%10;   //"1" count > point
		}
		base = 0;
	}
    //out
	void add_out(){
		out += 1;
	}
};	

int main(){

	int N;
	std::cin >> N;

	for(int i = 0; i < N; ++i){

		Baseball baseball(0, 0, 0);

		while(true){
			std::string str;
			std::cin >> str;

			if(str == "HIT") baseball.hit();
			
			else if(str == "HOMERUN") baseball.home_run();

			else if(str == "OUT"){
				baseball.add_out();
			
				if(baseball.get_out() == 3)
					break;
				
			}
		}
	std::cout << baseball.get_point() << std::endl;
	}

	return 0;
}

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

using namespace std;

int main()
{
	int i,n,point=0;
	bool run[3];
	string s;
	cin >> n;
	int out=3;
	while(n--){
		for(i=0;i<3;i++) run[i]=0;
		point=0;
		out=3;
		while(out){
			cin >> s;
			if(s == "HIT"){
				if(run[2])point++;
				for(i=2;i>0;i--) run[i]=run[i-1];
				run[0]=1;
				}
				else if(s == "HOMERUN"){
					for(i=0;i<3;i++) if(run[i]){ point++; run[i]=0;}
					point++;
				}
				else out--;
		}
	cout << point << endl;
	}
	return 0;
}