Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	var inning int

	fmt.Scanf("%d", &inning)

	score := make([]int, inning)

	for i := 0; i < inning; i++ {
		var outCount, runnerCount int

		for scanner.Scan() {
			event := scanner.Text()

			// HIT, HOMERUN, OUT
			switch event {
			case "HIT":
				runnerCount++
				if runnerCount > 3 {
					runnerCount--
					score[i]++
				}
			case "HOMERUN":
				score[i] += runnerCount + 1
				runnerCount = 0
			case "OUT":
				outCount++
			}

			if outCount == 3 {
				break
			}
		}
	}

	for _, v := range score {
		fmt.Println(v)
	}
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<queue>
#include <algorithm>
#include<functional>
#include<cstdlib>
#include<cmath>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define CI cin >>
#define CO cout <<
#define E << endl;

using namespace std;

typedef pair<int, int> P;
typedef pair<long, long> LP;
typedef pair<int, P> PP;
typedef pair<long, LP> LPP;



int dy[] = { 0, 0, 1, -1, 0 };
int dx[] = { 1, -1, 0, 0, 0 };

int A = 0, B = 0, C = 0, K = 0, S = 0, T = 0, W = 0, N = 0;
int n = 0;
double ar = 0, br = 0, cr = 0;
int answer = 0;

string c;
string sA, strB;
vector<string> city;
vector<int> population;


void input() {
	CI c;
	
}

int main(void) {
	
	int HIT = 0;
	int OUT = 0;
	bool HOMERUN = false;
	int point = 0;

	CI n;
	REP(i, n) {
		while (true) {
			CI c;
			if (c == "HIT") {
				HIT++;
			}
			if (c == "OUT") {
				OUT++;
			}
			if (c == "HOMERUN") {
				HOMERUN = true;
			}

			if (HIT == 4) {
				point++;
				HIT--;
			}
			if (HOMERUN == true) {
				point += HIT + 1;
				HIT = 0;
				HOMERUN = false;
			}
			if (OUT == 3) {
				HIT = 0;
				OUT = 0;
				break;
			}
		}
		CO point E
		point = 0;
	}
	

	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 get_score() {return score;}
    u_int get_out() {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.get_out() != 3){
            std::string event;
            std::cin >> event;
            
            // check 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; //show score
    }
    
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int score = 0, out = 0;
        int bases[3] = {};
        while (true) {
            char event[8];
            cin >> event;
            if (strcmp(event, "OUT") == 0) {
                out++;
                if (out == 3) {
                    break;
                }
            } else if (strcmp(event, "HIT") == 0) {
                score += bases[2];
                bases[2] = bases[1];
                bases[1] = bases[0];
                bases[0] = 1;
            } else if (strcmp(event, "HOMERUN") == 0) {
                score += bases[0] + bases[1] + bases[2] + 1;
                bases[0] = bases[1] = bases[2] = 0;
            }
        }
        cout << score << endl;
    }
}

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

int main(){
   int n,i,l,count,point;
   string hantei;
   queue<int> runner;
   
   cin>>n;
   for(i=0;i<n;i++){
      
      while(!runner.empty()) runner.pop();
      for(l=0;l<3;l++) runner.push(0);
      count=0;point=0;
      
      while(count!=3){
         cin>>hantei;
         
         if(hantei=="HIT"){
            runner.push(1);
            if(runner.front()==1) point++;
            runner.pop();
         }
         else if(hantei=="HOMERUN"){
            runner.push(1);
            for(l=0;l<3;l++) runner.push(0);
            
            for(l=0;l<4;l++){
               if(runner.front()==1) point++;
               runner.pop();
            }
         }
         else if(hantei=="OUT")
            count++;
      }
      cout<<point<<endl;
   }
   return 0;
}

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

int main()
{
	int n,inning=0;
	int inningp[34];
	string ivent;

	cin >> n ;
	while (n--)
	{
		int r=0, p=0, o=3;                        //r = ???????????????p = ?????????o = ??¢???????????°
		while (o)
		{
			cin >> ivent;

			if (ivent == "HIT")
			{
				r++;
				if (r >= 4)                       //??????
				{
					p++;
				}
			}

			else if (ivent=="HORMRUN")
			{
				if (r >= 4)                       //?????? = ???????????? + ????????????(1???)
				{
					p += 4;
				}
				else
				{
					p += r + 1;
				}
				r = 0;                            //??????????????????????????????
			}
			else if (ivent=="OUT")
			{
				o--;
			}
		}

		inningp[inning] = p;                      
		inning++;

	}

	for (int i = 0; i < inning; i++)
	{
		cout << inningp[i] << endl;
	}

	return 0;
}

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

using namespace std;

int main(int argc, char *argv[]) {
  int n;
  cin >> n;

  for (int i = 0; i < n; i++) {
    string s;
    bool runner[4] = {0};
    int score = 0, out = 0;
    while (true) {
      cin >> s;
      if (s == "HIT") {
        for (int j = 0; j <= 4; j++)
          runner[3-j] = (3-j == 0 ? true : runner[2-j]);
        if (runner[3]) {
          runner[3] = false;
          score++;
        }
      } else if (s == "HOMERUN") {
        score++;
        for (int j = 0; j < 3; j++)
          if (runner[j]) {
            runner[j] = false;
            score++;
          }
      } else {
        out++;
      }
      if (out >= 3) {
        cout << score << endl;
        break;
      }
    }
  }
  return 0;
}

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

using namespace std;

int main(){
    int n;
    string s;
    int flag=0,count=0,rui=0;
    cin>>n;
    while(flag<n*3){
        cin>>s;
        if(s=="OUT"){
            flag++;
            if(flag%3==0){
                cout<<count<<endl;
                count=0;rui=0;
            }
        }
        else if(s=="HIT"){
            if(rui<3)rui++;
            else count++;
        }
        else {
            count+=rui;++count;
            rui=0;
        }
    }
}