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>

int main(){
    int hit, out, score, data_set_num;
    std::string event;
    cin >> data_set_num;


    while(data_set_num--){
        cin >> event;
        if(event == "HIT"){
            ++hit;
            if(hit == 4){
                ++score;
                hit = 3;
            }
        }else if(event == "HOMERUN"){
            score += (hit + 1);
            hit = 0;
        }else if(event == "OUT"){
            ++out;
        }

        if(out == 3){
            std::cout << score << std::endl;
            hit = 0;
            core = 0;
        }
    }

    return 0;
}

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;
}