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 <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;
            if(event == "HIT"){
                game.hit();
            }
            else if(event == "HOMERUN"){
                game.homerun();
            }
            else if(event == "OUT"){
                game.out();
            }
        }
        std::cout << game.get_score() << std::endl;
    }
    return 0;
}

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

class Baseball{
private:
    int m_first = 0;
    int m_second = 0;
    int m_third = 0;
    int m_out = 0;
    int m_point = 0;

public:
    void isHit(){
        if(m_third == 1){
            m_third = 0;
            ++m_point;
        }
        if(m_second == 1){
            m_second = 0;
            m_third = 1;
        }
        if(m_first == 1){
            m_second = 1;
        }
        else {
            m_first = 1;
        }
    }
    void isHomerun(){
        m_point += m_first + m_second + m_third + 1;
        m_first = 0;
        m_second = 0;
        m_third = 0;
    }
    void setOut(){
        ++m_out;
    }
    int getOut(){
        return m_out;
    }
    int getPoint(){
        return m_point;
    }
};

int main(){
    int n;
    std::string event;

    std::cin >> n;
    Baseball baseball[n];
    //std::array<Baseball, n> baseball;
    for(int i = 0; i < n; ++i){
        while(baseball[i].getOut() < 3) {
            std::cin >> event;
            if (event == "HIT") {
                baseball[i].isHit();
            } else if (event == "OUT") {
                baseball[i].setOut();
            } else if (event == "HOMERUN"){
                baseball[i].isHomerun();
            }
        }
        std::cout << baseball[i].getPoint() << std::endl;
    }
}

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

int main(){
	bool F,S,T;
	int out,point;
	
	int i,j;
	
	int dataN,dataLoop;
	string E;
	
	cin>>dataN;
	for(dataLoop=0;dataLoop<dataN;dataLoop++){
	out=0;point=0;
	while(out==3){
	 cin>>E;
	 if(E=="HIT"){
	  if(T){point++;}
	  T=S;S=F;F=true;
	 }else if(E=="HOMERUN"){
	  point++;
	  if(F){point++;F=false;}
	  if(S){point++;S=false;}
	  if(T){point++;T=false;}
	 }else{
	  out++;
	 }
	}
	cout<<point<<endl;
	}
	
	return 0;
}

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

using namespace std;
 
int main(int argc, char **argv) {
    int n, out, hit, total;
    string s;
    cin >> n;
     
    for (int i = 0; i < n; ++i) {
        out = 0;
        hit = 0;
        total = 0;

        while (out < 3) {
            cin >> s;

            if (s == "HIT") {
                if (hit == 3) total++;
                else hit++;
            } 
            else if (s == "HOMERUN") {
                total += hit + 1;
                hit = 0;
            } 
            else {
                out++;
            }
        }
        cout<<total<<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MAX 9999999
using namespace std;
typedef struct{
    int count;
    string s="OUT";
}OUT;
typedef struct{
    int count;
    string s="HOMERUN";
}HOME;
typedef struct{
    int count;
    string s="HIT";
}HIT;
typedef struct{
    int count;
}RUN;
typedef pair<int, int> pii;
int main(){
    int n; cin>>n;
    pii score=pii(0,0); bool now=true;
    OUT out; HOME home; HIT hit; RUN run;
    out.count=0; home.count=0; hit.count=0; run.count=0;
    string temp;
    while(cin>>temp){
        if(temp==out.s){out.count++; if(out.count==(3*n))goto E;if(out.count%3==0){now=(!now);run.count=0;};}
        if(temp==home.s){
            if(now)score.first+=run.count+1;
            else score.second+=run.count+1;
            run.count=0;
        }
        if(temp==hit.s){
            run.count++;
            if(run.count>3){if(now)score.first++; else score.second++; run.count-=1;}
        }
    }
E:;cout<<score.first<<"\n"<<score.second<<endl;
}

C++: #include<iostream>
#include<vector>
int main(){
	int n,m=0;
	std::cin>>n;
	int o=0;
	std::vector<int> vec(3);
	std::vector<int> vec2(n);
	while(n>m){
		int d=0;
		std::string str;
		std::cin>>str;
		if(str=="HIT"){
			if(vec[2]==1)vec2[d]++,vec[2]=0;
			if(vec[1]==1)vec[2]=1,vec[1]=0;
			if(vec[0]==1)vec[1]=1,vec[0]=0;
			vec[0]=1;
		}
		if(str=="HOMERUN"){
			for(int i=0;i<3;i++){
				if(vec[i]==1)vec2[d]++;
				vec[i]=0;
			}
			vec2[d]++;
		}

		if(str=="OUT")o++;
		if(o==3){
			m++,o=0,d++;
			for(int i=0;i<3;i++){
				vec[i]=0;
			}
		}
	}
	for(int i=0;i<n;i++){
		std::cout<<vec2[i]<<std::endl;
	}
	return 0;
}

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

int main()
{
  int n;
  cin >> n;

  string s;
  int runner = 0, out = 0, score = 0;
  while (cin >> s) {
    if (s == "OUT") {
      ++out;
      if (out >= 3) {
	cout << score << endl;
	runner = out = score = 0;
      }
    } else if (s == "HIT") {
      ++runner;
      if (runner > 3) {
	++score;
	--runner;
      }
    } else {
      score += runner + 1;
      runner = 0;
    }
  }
  return 0;
}

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

int main(){
  int n,cou=0;
  string str;
  cin >> n;
  while(n>cou){
    int cou_out=0,ans=0,ining=0;
    while(cou_out < 3){
      cin >> str;
      if(str == "HIT"){
	ining++;
	if(ining == 4){
	  ans++;
	  ining--;
	}
      }
      else if(str == "OUT"){
	cou_out++;
      }
      else if(str == "HOMERUN"){
	ans += ining+1;
	ining = 0;
      }
    }
    cou++;
    cout << ans << endl;
  }
}

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

using namespace std;

int main()
{
	int n, i, score=0, hit=0, out=0;
	string s;
	
	cin >> n; cin.get();
	
	for (i=0; i<n;) {
		getline(cin, s);
		if (s == "HIT") {if (++hit == 4) {score++; hit--;}}
		else if (s == "HOMERUN") {score += hit+1; hit = 0;}
		else if (s == "OUT") {if (++out == 3) {out=0; hit = 0; cout << score << endl; score=0; i++;}}
	}
	return 0;
}