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>

class Baseball{

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

public:

	Baseball(){
		point = 0;
		out = 0;
		base = 0;
	}

	int point(){
		return point;
	}

	int out(){
		return out;
	}

	void hit(){
		base = (base * 10) + 1;
		
		if(base >= 1000){
			base -= 1000;
			point += 1;
		}
	}

	void home_run(){
		point += 1;
		for(int i = base; i > 0; i /= 10){
			point += i%10;
		}
		base = 0;
	}

	void get_out(){
		out += 1;
	}
};	

int main(){

	int N;
	std::cin >> N;

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

		while(baseball.out() != 3){
			std::string str;
			std::cin >> str;

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

			else if(str == "OUT")
				baseball.get_out();

		}

		std::cout >> baseball.point() >> std::endl;
	}

	return 0;
{

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

using namespace std;
#define ALLAY_SIZE(a)  sizeof((a))/sizeof(*(a))

enum BASE_NO{
  FIRST = 0,
  SECOND,
  THIRD,

  BASE_NUM
};

enum PUT_IN {
  HIT = 0,
  HOMERUN,
  OUT,

  IN_NUM
};
static const string put_in[IN_NUM]{
  "HIT",
  "HOMERUN",
  "OUT"
};

class Base
{
public:
  Base() { Reset(); }
  void BaseIn(int base) { base_exist[base] = true; }
  void BaseOut(int base) { base_exist[base] = false; }
  bool IsBaseIn(int base) { return base_exist[base]; }
  bool Rotate() { 
    bool add_score;

    // ??????????????????????????????
    for (int i = THIRD; i >= 0; i--) {
      int next_base = i + 1;
      
      // ???????????°??????????????´??????TRUE?????????
      if (i == THIRD) add_score = IsBaseIn(i);
      else            base_exist[next_base] = base_exist[i];
    }

    return add_score;
  }
  int Reset() {
    // ?????????????????????reset???????????°?????????
    int runnner_count = 0;
    for (int i = 0; i < ALLAY_SIZE(base_exist); i++) {
      if (IsBaseIn(i)) runnner_count++;
      BaseOut(i);
    }
    
    return runnner_count;
  }
private:
  bool base_exist[BASE_NUM];
};

class BaseballGame
{
public:
  BaseballGame() : score(0), out_count(0), is_game_end(false) {}
  void Hit() {
    //  ???????????????????????¬????????°?????????????????°?????????????¶???????
    if (base.Rotate())
      score++;
    //  ???????????????????????????????????????
    base.BaseIn(FIRST);
  }
  void Homerun() {
    //  ??°?????°??????????????????
    Hit();
    //  ???????????°?????¨????????¬????????????
    int add_score = base.Reset();
    // ?????????????????°????????°??????????????????
    score += add_score;
  }
  void Out() {
    // ??¢???????????????????????????
    out_count++;
    // ??¢?????????????????????3??????????????¨??????????????°??????
    if (out_count >= GAMEEND_OUT_NUM)
      is_game_end = true;
  }

  int   GameScore() {
    return score;
  }
  bool  IsGameEnd() {
    return is_game_end;
  }
private:
  static const int GAMEEND_OUT_NUM = 3;

	int   score;
  int   out_count;
  Base  base;
  bool  is_game_end;
};

int main() {
  int game_num;
  cin >> game_num;
  for (int i = 0; i < game_num; i++) {
    BaseballGame game;
    while (!game.IsGameEnd()) {
      string in_data;
      cin >> in_data;

      if (in_data == put_in[HIT])
        game.Hit();
      else if (in_data == put_in[HOMERUN])
        game.Homerun();
      else if (in_data == put_in[OUT])
        game.Out();
    }
    cout << game.GameScore() << endl;
  }
}

C++: #include <bits/stdc++.h>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ELEM(array) (sizeof (array)/sizeof *(array))
#define MAX_N 100
typedef long long ll;

int n;
int count_HIT=0, count_OUT=0;
int Point=0;
string S;


void solve()
{
	while (count_OUT <3)
	{
		cin >> S;
		if (S == "HIT")
		{
			count_HIT++;
			if (count_HIT == 4)
			{
				Point[++;
				
				count_HIT -- ;
			}
		}
		else if (S == "HOMERUN")
		{
			Point += count_HIT + 1;
			
			count_HIT = 0;
		}
		else count_OUT++;
	}
	cout << Point << endl;
	count_OUT = 0; count_HIT = 0;
	Point = 0;
	
	return;
}

int main()
{
	cin >> n;
	REP(j, n)
	{
		solve();
	}

	

	return 0;
}

C++: #include<iostram>
#include<cstdio>
#include<algorithm>
using namespace std;
main(){
int N;
scanf("%d",&N);
for(int i=;i<N;i++){
int oc=0;
int po=0;
int co[3]={0};

while(oc<3){
string str;
cin >> str;
if(str=="OUT") oc++;
if(str=="HIT"){
po+=co[2];
co[2]=co[1];
co[1]=co[0];
co[0]++;
}
if(str=="HOMERUN"){
po+=co[0]+co[1]+co[2]+1;
}
}
cout << po << endl;

}
}

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

#define REP(i,a,n) for(i=a; i<n; i++)
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define foreach(it,x) for(typeof(x.begin()) it=x.begin(); it!=x.end(); it++)


int main(){
    int run=0, out=0, point=0;
    int t; cin >> t;
    string in;

    while ( cin >> in ){
        if( in == "HIT" ){
            run++;
            if( run >= 4 ){
                run--; point++;
            }
        }
        else if( in == "OUT" ){
            out++;
        }
        else if( in == "HOMERUN" ){
            point += run + 1;
            run = 0;
        }

        if( out == 3 ){
            printf("%d\n",point);
            run = out = point = 0;
        }
    }

    return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main(){
    int n;
    string ins;
    cin>>n;
    for(int ix=0;ix<n;ix++){
        int out=0,po=0;
        vector<bool> runner(3,false);
        for(;;){
            cin>>ins;
            if(ins=="HIT"){
                if(runner[2]){
                    po++;
                    runner[2]=false;
                }
                if(runner[1]){
                    runner[2]=true;
                    runner[1]=false;
                }
                if(runner[0]) runner[1]=true;
                runner[0]=true;
            }else if(ins=="OUT"){
                out++;
                if(out==3)break;
            }else if(ins=="HOMERUN"){
                po++;
                for(int i=0;i<3;i++){
                    if(runner[i])po++;
                    runner[i]=false;
                }
            }
        }
        cout<<po<<endl;
    }
}

C++: #include <bits/stdc++.h>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ELEM(array) (sizeof (array)/sizeof *(array))
#define MAX_N 100
typedef long long ll;

int n;
int count_HIT=0, count_OUT=0;
int Point[2] = {0,0};
int i=0;
string S;

void solve()
{
	while (count_OUT == 3)
	{
		cin >> S;
		if (S == "HIT"){
			count_HIT++;
			if (count_HIT == 4)
			{
				Point[i]++;
				count_HIT = 0;
			}
		}
		else if (S == "HOMERUN")
		{
			Point[i] = count_HIT + 1;
			count_HIT = 0;
		}
		else count_OUT++;
	}
	count_OUT = 0; count_HIT = 0;
	i ^= 1;
	n++;
	return;
}

int main()
{
	cin >> n;
	REP(i, n)
	{
		solve();
	}

	cout << Point[0] << endl
		<< Point[1] << endl;

	return 0;
}