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 <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[2] = {0,0};
int i=0;
string S;



int main()
{
	cin >> n;
	REP(i, n)
	{
		while (count_OUT == 3)
		{
			cin >> S;
			if (S == "HIT"){
				count_HIT++;
				if (count_HIT == 4)
				{
					Point[i]++;
					count_HIT = 0;
				}
			}
			else if (S == "HOMERUN")
			{
				Point[i] = count_HIT + 1;
				count_HIT = 0;
			}
			else count_OUT++;
		}
		count_OUT = 0; count_HIT = 0;
		i ^= 1;
		n++;
	}

	cout << Point[0] << endl
		<< Point[1] << endl;

	return 0;
}

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

int main(){
    int hit, out, score, data_set_num;
    std::string event, str;
    std::getline(std::cin,str);
    sscanf(str.c_str(),"%d ",&data_set_num);

    while(data_set_num){
        std::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;
            score = 0;
            out = 0;
            --data_set_num;
        }
    }

    return 0;
}

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

class Baseball {

	std::array<bool, 3> base;//base[0]:first, base[1]:second, base[2]:third
	int point,outcount,inning;

public:
	/*construtor*/
	Baseball(int ing) {
		for (int i = 0; i < (int)base.size(); ++i){
			base[i] = false;
		}
		point = 0;
		outcount = 0;
		inning = ing;
	}

	int inning_result(std::string res);

private:
	void clear();
	void hit();
	void homerun();
	void out();
};

/*Clear method*/
void Baseball::clear() {

	for (int i = 0; i < (int)base.size(); ++i){
		base[i] = false;
	}

	point = 0;
	outcount = 0;

}

/*The case of hit*/
void Baseball::hit() {

	if (base[2] == true) {
		++point;
		base[2] = false;
	}

	if (base[1] == true){
		base[2] = true;
		base[1] = false;
	}

	if (base[0] == true) {
		base[1] = true;
		base[0] = false;
	}

	base[0] = true;

}

/*The case of homerun*/
void Baseball::homerun() {

	++point;//butter runner point

	for (int i = 0; i < (int)base.size(); ++i){
		if (base[i] == true){
			++point;
		}
		base[i] = false;
	}

}

/*The case of out*/
void Baseball::out() {

	++outcount;

	if (outcount == 3){
		std::cout << point << std::endl;
		clear();
		--inning;
	}

}

/*Judgement of inning*/
int Baseball::inning_result(std::string res) {

	if (res == "HIT") {
		hit();
	}
	else if (res == "HOMERUN") {
		homerun();
	}
	else if (res == "OUT") {
		out();
	}
	else {
		std::perror(NULL);
	}

	return inning;
}

int main() {

	int n;//the number of ining
	std::string result;

	std::cin >> n;

	Baseball game(n);

	while (n > 0) {
		std::cin >> result;
		n = game.inning_result(result);
	}

	return 0;
}

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

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

C++: #include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<cstdio>
typedef unsigned long long ull;
#define rep(i,a) for(int i=0;i<a;i++)
#define loop(i,a,b) for(int i=a;i<b;i++)
using namespace std;
const double eps = 1e-10;
const double pi = acos(-1);
const double inf = (int)1e8;

int main(void){
  string str;
  int base=0,point=0,out=0;
  int n;
  cin>>n;
  getline(cin,str);
  while(getline(cin,str)){
    if(str[0] == 'O'){
      out++;
      //cout<<out<<endl;
      if(out==3){
	n--;
	printf("%d\n",point);	
	base=0,point=0,out=0;
	if(n==0)break;
      }
    }
    else if(str[1] == 'I'){
      base ++;
      if(base>3){
	base --;
	point ++;
      }
    }
    else if(str[1] == 'O'){
      point += base + 1;
      base = 0;
    }

  }
  return 0;
}

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

int main()
{
	int point, base, n, out;
	string ibe;

	cin >> n;
	for (int k = 0; k < n; k++){
		base = point = out = 0;
		while (1){
	 	 cin >> ibe;
		 if (ibe == "HIT"){
			 base++;
			 if (base == 4){
				 base--;
				 point++;
			 }
		 }
		 else if (ibe == "OUT"){
			 out++;
		 }
		 else {
			 point += base + 1;
			 base = 0;
		 }
		 if (out >= 3) break;
		 
		}
		cout << point << endl;
	}
	return (0);
}