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 <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main() {
  int n = 0, tmp0 = 0, tmp1 = 0;
  int HB = 0, out = 0, point = 0;
  string str;
  scanf("%d", &n);
  // for(tmp0=0;tmp0<3;tmp0++) HB[tmp0]=0;
  while (n) {
    point = 0, HB = 0, out = 0;
    while (out < 3) {
      cin >> str;
      if (str=="OUT") out++;
      else if (str=="HIT") {
        HB++;
        if (HB==4) {
          HB--;
          point++;
        }
      } else if (str=="HOMERUN") {
        point += HB + 1;
        HB = 0;
      }
    }
    printf("%d\n", point);
    n--;
  }
  return 0;
}

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

int base;

int hit(){
	if(base==3) return 1;
	else base++;
	return 0;
}

int homerun(){
	base++;
	return base;
}

int main(){
	int inning;
	std::cin << inning;

	for(int i=0;i<inning;i++){
		int outCount=0;
		int point=0;
		string result;
		base=0;
		while(outCount<3){
			std::cin << result;

			if(result == "HIT"){
				point += hit();
			} else if(result == "HOMERUN"){
				point += homerun();
				base=0;
			} else if(result == "OUT"){
				outCount++;
			}
		}
		std::cout >> point >> std::endl;
	}

    return 0;
}

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

int base[3] = { 0,0,0 };
int score = 0;
int out = 0;

int hit()
{
	score += base[2];
	base[2] = base[1];
	base[1] = base[0];
	base[0] = 1;
	return 0;
}

int homerun()
{
	for (int i = 0; i < 3; i++)
	{
		score += base[i];
		base[i] = 0;
	}
	score++;
	return 0;
}

int outf()
{
	out++;
	if (out > 2)
	{
		out = 0;
		cout << score << endl;;
		score = 0;
		base[0] = base[1] = base[2] = 0;
	}
	return 0;
}

int main()
{
	int n;
	cin >> n;
	string state;
	while (cin >> state)
	{
		if (state == "HIT")
			hit();
		else if (state == "HOMERUN")
			homerun();
		else if (state == "OUT")
			outf();
	}

	return 0;
}

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, 2) {
		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<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    int n;
    string ju;
    int result[2000]={0};
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int hit=0,out=0;
        while(1){
            cin>>ju;
            if(ju[0]=='H'&&ju[1]=='I'){
                if(hit<3)
                    hit++;
                else
                    result[i]++;
            }
            else if(ju[1]=='O')
                result[i]+=(hit+1),hit=0;
            else
                out++;
            if(out==3)
                break;
        }
    }
    for(int i=0;i<n;i++)
        printf("%d\n",result[i]);
    return 0;
}

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

int Baseball()
{
    int num_of_runner = 0, num_of_out = 0, point = 0;
    std::string event;
    
    while(num_of_out != 3){
        std::cin >> event;
        if(event == "HIT"){
            if(num_of_runner == 3)
                ++point;
            else
                ++num_of_runner;
        }
        else if(event == "HOMERUN"){
            point += 1 + num_of_runner;
            num_of_runner = 0;
        }
        else
            ++num_of_out;
    }
    
    return point;
}

int main()
{
    u_int num_of_inning;
    std::cin >> num_of_inning;
    
    for(u_int i = 0; i < num_of_inning; ++i){
        std::cout << Baseball() << std::endl;
    }
    
    return 0;
}

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

class Baseball{
    private:
        std::queue<int> runner;
        int out_count;
        int score;
        
    public:
        void initRunner(){
            while(runner.empty() != true){
                runner.pop();
            }
            for(int i = 0; i < 3; ++i){
                runner.push(0);
            }
        }
        
        Baseball(){
            out_count = 0;
            score = 0;
            initRunner();
        }
        
        ~Baseball(){}
        
        void hit(){
            if(runner.front() == 1) ++score;
            runner.pop();
            runner.push(1);
        }
        
        void homerun(){
            do{
                if(runner.front() == 1) ++score;
                runner.pop();
            } while (runner.empty() != true);
            ++score;
            initRunner();
        }
        
        int getScore(){
            initRunner();
            std::string str;
            while(out_count != 3){
                std::cin >> str;
                if(str == "HIT") hit();
                if(str == "HOMERUN") homerun();
                if(str == "OUT") ++out_count;
            }
            return score;
        }
};

int main(void){
    int N;
    std::cin >> N;
    for(int i = 0; i < N; ++i){
        Baseball baseball;
        std::cout << baseball.getScore() << std::endl;
    }
}

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

using namespace std;

int main(){
        int N;
        int out=0;
        cin>>N;
        N*=3;
        string str;
        int ans=0;
        int run=0;
        while(out<N){
                cin>>str;
                if(str=="HIT"){
                        run++;
                        if(run>=4){
                                ans++;
                                run--;
                        }
                }
                else if(str=="OUT"){
                        out++;
                        if(out%3==0){
                                cout<<ans<<endl;
                                ans=0;
                                run=0;
                        }
                }
                else if(str=="HOMERUN"){
                        run++;
                        ans+=run;
                        run=0;
                }
        }

return 0;
}