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 <iostream>
#include <string>

class Baseball{
private:
	int first;
	int second;
	int third;
	int score;
	int count;
public:
	Baseball(){
		first=0;
		second=0;
		third=0;
		score=0;
		count=0;
	}
	int getScore(){
		return score;
	}
	void hit(){
		score+=third;
		third=second;
		second=first;
		first=1;
	}
	void homerun(){
		score+=third+second+first+1;
		first=0;
		second=0;
		third=0;
	}
	void out(){
		count++;
	}
	int getCount(){
		return count;
	}
};

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

	for(int i=0;i<inning;i++){
		Baseball attack;
		std::string result;
		while(attack.getCount()<3){
			std::cin >> result;

			if(result == "HIT"){
				attack.hit();
			} else if(result == "HOMERUN"){
				attack.homerun();
			} else if(result == "OUT"){
				attack.out();
			}
		}
		std::cout << attack.getScore() <<std::endl;
	}

    return 0;
}

C++: #include <iostream>
#include <map>
#include <functional>

int main(int argc, char const* argv[])
{
	std::map<std::string, std::function<void(void)>> tab;
	uint8_t runner{};
	unsigned outcount{};
	unsigned point{};

	tab["HIT"] = [&](){ runner <<= 1; runner |= 1; if(runner & 0x08) ++point; };
	tab["OUT"] = [&](){ ++outcount; };
	tab["HOMERUN"] = [&](){ ++point; if(runner & 0x01) ++point; if (runner & 0x02) ++point; if (runner & 0x04) ++point; runner = 0; };
	tab[""] = [](){  };

	unsigned n;
	std::cin >> n;
	while (n--) {
		while (outcount<3) {
			std::string s{};
			std::cin >> s;
			tab[s]();
		}
		std::cout << point << std::endl;
		runner = 0;
		outcount = 0;
		point = 0;
	}
	
	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
	int a,b,c,d;
	int score;
	int out=0;
	int n;
	cin>>n;
	while(n--){
		score=a=b=c=d=0;
		out=0;
		string e;
		while(out!=3){
			cin>>e;
			if(e=="HIT"){
				d=c;c=b;b=a;a=1;
				score+=d;d=0;	
			}else if(e=="HOMERUN"){
				score += a+b+c+1;
				a=b=c=0;
			}else{
				out++;
			}
		}
		cout<<score<<endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
 int n;
 cin>>n;
 while(n){
  int o=0,a=0,b=0;
  while(o!=3){
   string s;
   cin>>s;
   if(s=="HIT"){
    if(b==3){
     a++;
    }
    else b++;
    }
   }
   else if(s=="OUT")o++;
   else{
   a+=++b;
   b=0;
   }
  }
  cout<<a<<endl;
  n--;
 }
}

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<iostream>
using namespace std;

int main(){
  int n;
  int point=0;
  int out_count=0;
  int runner=0;
  cin>>n;
  string event;
  for(int i=0;i<n;i++){
    out_count=0;
    point=0;
    runner=0;
    while(out_count<3){
      cin>>event;
      if(event=="HIT"){
	runner++;
	if(runner>3){
	  point++;
	  runner--;
	}
      }else if(event=="OUT"){
	out_count++;
      }else{
	point+=runner+1;
	runner=0;
      }
    }
    cout << point << endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

int main(void){

	int n;
	cin >> n;

	int runner = 0;
	int result = 0;

	int i = 0;
	while(i < n * 3){

		string buff;
		cin >> buff;

		if (buff == "HIT"){
			runner++;
			if (runner > 3){
				result++;
				runner = 3;
			}
		}
		else if (buff == "OUT"){
			i++;
			if (i % 3 == 0){
				cout << result << endl;
				runner = 0;
				result = 0;
			}
		}
		else if (buff == "HOMERUN") {
			result += (runner + 1);
			runner = 0;
		}

	}

	return 0;
}

C++: #include<iostream>
#include<math.h>
using namespace std;

int main(){
    int n;
    cin>>n;
    for(int i=0; i<n; i++){
        bool base[3]={};
    int out=0;
        int ans=0;
    string str;
    while(out!=3){
        cin>>str;
        if(str=="HIT"){
            if(base[2])ans++;
            base[2]=false;
            swap(base[1],base[2]);
            swap(base[1],base[0]);
            base[0]=1;
        }
        if(str=="HOMERUN"){
            for(int i=0; i<3; i++){
                if(base[i])ans++;
                base[i]=false;
            }
            ans++;

        }
        if(str=="OUT")out++;
    }
        cout<<ans<<endl;
    }
    return 0;
}

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


using namespace std;

class Player{
private:
  int  base;

public:
  Player(int i){
    base=1;
  }


  void SetBase(int a){
    this->base =a;
  }

  int GetBase(){
    return this->base;
  }
};

class Baseball{
private:
  int score;
  int out;
  queue<Player> que;

public:
  Baseball(){
      score = out=0;
  }

  void add_hit(int num){
    Player one(1);
    this->que.push(one);
    int length=this->que.size();

    for(int i= 0;i<length;i++){
      Player tmp = this->que.front();
      this->que.pop();
      int tmp_base=tmp.GetBase();
      if((tmp_base+num)>4){
        score++;
      }else{
        tmp.SetBase(tmp_base+num);
        this->que.push(tmp);
      }
    }
  }

  void add_out(){
    this->out++;
  }

  void add_score(){
    this->score++;
  }

  int GetOut(){
    return this->out;
  }

  int GetScore(){
    return this->score;
  }




  void show_score(){
    cout<<this->score<<endl;
  }

};

int main(void){
  int time;
  cin >> time;

  for(int i=0;i<time;i++){
    Baseball baseball;
    while(baseball.GetOut()!=3){
      string judge;
      cin>>judge;
      if(judge == "HIT"){
        baseball.add_hit(1);
      }else if(judge=="OUT"){
        baseball.add_out();
      }else if(judge=="HOMERUN"){
        baseball.add_score();
      }

    }

    cout<<baseball.GetScore()<<endl;
  }

  return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main()
{
	int out = 0;
	int r1 = 0;
	int r2 = 0;
	int r3 = 0;
	int t = 0;
	string k;
	int a = 0;
	cin >> a;
	for (int i = 1; i <= a; i++)
	{
		out = 0;
		t = 0;
		r1 = 0;
		r2 = 0;
		r3 = 0;
		while (out != 3)
		{
			cin >> k;
			if (k == "OUT")
			{
				out++;
			}
			if (k == "HIT")
			{
				if (r3 == 1)
				{
					t++;
					r3 = 0;
				}
				if (r2 == 1)
				{
					r3 = 1;
					r2 = 0;
				}
				if (r1 == 1)
				{
					r2 = 1;
					r1 = 0;
				}
			}
			if (k == "HOMERUN")
			{
				if (r3 == 1)
				{
					t++;
					r3 = 0;
				}
				if (r2 == 1)
				{
					t++;
					r2 = 0;
				}
				if (r1 == 1)
				{
					t++;
					r1 = 0;
				}
				t++;

			}
		}
		cout << t << endl;
	}
	return 0;
}