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 <vector>
#include <string>
#include <cstdio>

using namespace std;

int main(){
	string ev[] = {"HIT", "OUT", "HOMERUN"};
	int n;
	cin >> n;
	while(n--){
		string s;
		int out = 0;
		int state = 0;
		int runner = 0;
		int point = 0;
		while(out < 3){
			cin >> s;
			if(s == ev[0]){
				state = state << 1;
				state++;
				if(state&(1<<3)){
					point++;
				}else{
					runner++;
				}
			}else if(s == ev[1]){
				out++;
			}else if(s == ev[2]){
				point += ++runner;
				state = 0;
				runner = 0;
			}
		}
		cout << point << endl;
	}

	return 0;
}

C++: #include <stdio.h>
#include <string.h>
int main(){
	int run,out,n,score;
	run=out=score=0;
	char eve[10];
	scanf("%d",&n);
	while(n--){
		while(out<3){
			scanf("%s",eve);
			if(strcmp(eve,"HIT")==0){
				run++;
				if(run>3) score++;
			}
			else if(strcmp(eve,"OUT")==0) out++;
			else if(strcmp(eve,"HOMERUN")==0){
				if(run>=3) run=3;
				score += run+1;
				run=0;
			}
		}
		printf("%d\n",score);
		run=out=score=0;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
&#160;
using namespace std;
&#160;
int main()
{
&#160;&#160;&#160;&#160;int n, o, h, t;
&#160;&#160;&#160;&#160;string s;
&#160;&#160;&#160;&#160;cin >> n;
&#160;&#160;&#160;&#160;&#160;
&#160;&#160;&#160;&#160;while(n--)
	{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;o = h = t = 0;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;while(o < 3)
		{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;cin >> s;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;if(s == "HIT")
			{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;if(h == 3)
				{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;t++;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;} 
				else 
				{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;h++;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;} else if(s == "HOMERUN")
			{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;t = t + h + 1;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;h = 0;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;} 
			else 
			{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;o++;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;cout << t << endl;
&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;&#160;
&#160;&#160;&#160;&#160;return 0;
}

C++: #include<stdio.h>
#include<string.h>
int out_cnt;
int base[4];
int point;
//■HITの処理
void hit()
{
	int temp[4];
	for(int f1=0;f1<3;f1++){
		temp[f1+1]=base[f1];
	}
	for(int f1=0;f1<4;f1++){
		base[f1]=temp[f1];
	}
	base[0]=1;
	if(base[3]==1){
		point++;
		base[3]=0;
	}
}
//■HOMERUNの処理
void homerun()
{
	for(int f1=0;f1<3;f1++){
		if(base[f1]==1){
			base[f1]=0;
			point++;
		}
	}
	point++;
}
//■OUTの処理
void out()
{
	out_cnt++;
}
//■データの表示
void show()
{
	printf("一塁:%d 二塁%d 三塁%d\n",base[0],base[1],base[2]);
	printf("得点:%d アウト数:%d\n",point,out_cnt);
}
//■メイン関数
int main(void)
{
	int inning;
	scanf("%d",&inning);
	while(inning>0){
		char temp[10];
		scanf("%s",temp);
		if(strcmp(temp,"HIT")==0){
			hit();
		}
		else if(strcmp(temp,"HOMERUN")==0){
			homerun();
		}
		else{
			out();
		}
		if(out_cnt==3){
			printf("%d\n",point);
			inning--;
			out_cnt=0;
			point=0;
			for(int f1=0;f1<4;f1++){
				base[f1]=0;
			}
		}
		//show();
	}
	return 0;
}

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

using namespace std;

int main(void){
	int game;
	cin >> game;
	for(int i = 0; i < game; i++){
		int out = 0;
		int base = 0;
		int point = 0;
		string n;
		while(out < 3){
			cin >> n;
			if(n == "HIT"){
				base++;
				if(base == 4)
				point++;
			}else if(n == "OUT"){
				out++;
			}else if(n == "HOMERUN"){
				point += base + 1;
			}
		}
		cout << point << endl;
	}
	
	return 0;
}

C++: #include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	int N=in();
	REP(i,N){
		int O=0,P=0;
		deque<int> R{0,0,0};
		while(O<3){
			string S=in<string>();
			if(S=="HIT"){
				if(R[0]==1) P++;
				rotate(R.begin(),R.begin()+1,R.end());
				R[2] = 1;
			}
			else if(S=="OUT"){
				O++;
			}
			else{
				int sum = accumulate(ALL(R),0);
				P += sum+1;
				fill(ALL(R),0);
			}
		}
		out(P);
	}
	
	return 0;
}

C++: #include <iostream>
#include <string>
#include <bitset>
   
class Baseball{
    u_int score, out_count;
    std::bitset<4> runners; 
public:
    Baseball() : score(), out_count(){} //initializer list
    ~Baseball() = default;
    void hit();
    void homerun();
    void out() {++out_count;}
    u_int getScore() {return score;}
    u_int getOutcount() {return out_count;}
};
  
void Baseball::hit(){
    runners <<= 1; //shift
    runners.set(0); //set runner
    if(runners.test(3)){
        ++score;
        runners.reset(3);
    }
}
  
void Baseball::homerun(){
    score += runners.count() + 1;
    runners.reset();
}
  
int main(){
    u_int inning;
    std::cin >> inning;
    for(u_int i = 0; i < inning; ++i){
        Baseball game;
        while(game.getOutcount() != 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.getScore() << std::endl;
    }
    return 0;
}