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<vector>
int main(){
	int n,m=0,n2=0,s1=0,s2=0;
	std::cin>>n;
	int o=0;
	std::vector<int> vec(3);
	while(n>m){
		std::string str;
		std::cin>>str;
		if(str=="HIT"&&n2%2==0){
			
			if(vec[2]==1)s1++;
			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=="HIT"&&n2%2==1){
			if(vec[2]==1)s2++;
			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"&&n2%2==0){
			for(int i=0;i<3;i++){
				if(vec[i]==1)s1++;
				vec[i]=0;
			}
			s1++;
		}
		if(str=="HOMERUN"&&n2%2==1){
			for(int i=0;i<3;i++){
				if(vec[i]==1)s2++;
				vec[i]=0;
			}
			s2++;
		}
		if(str=="OUT")o++;
		if(o==3){
			m++,o=0,n2++;
			for(int i=0;i<3;i++){
				vec[i]=0;
			}
		}
	}
	std::cout<<s1<<std::endl<<s2<<std::endl;
	return 0;
}

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

int main(){
	int n;
	cin >> n;
	for(int p=0; p < n; p++){
		int score = 0, out = 0, run[5];
		string event;
		fill(run, run+5, 0);

		while(1){
			cin >> event;
			if(event == "HIT"){
				run[0] = 1;
				for(int i=3; 0 <= i; i--){
					if(run[i] == 1) swap(run[i], run[i+1]);
				}
				if(run[4] == 1){
					score++;
					run[4] = 0;
				}
			}
			if(event == "HOMERUN"){
				run[0] = 1;
				for(int i=0; i < 4; i++){
					if(run[i] == 1){
						score++;
						run[i] = 0;
					}
				}
			}
			if(event == "OUT") out++;
			if(out == 3) break;
		}
		cout << score << endl;
	}
}

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

using namespace std;

void outputAsBinary(unsigned char data)
{
	for(int i = 0;i < 8;i++)
	{
		if(data & (0x01 << i)) cout << "1";
		else cout << "0";
	}
	cout << endl;
}

int main()
{
	int n;
	cin >> n;
	for(int i = 0;i < n;i++)
	{
		int out = 0;
		int score = 0;
		unsigned char data = 0;
		while(1)
		{
			string event;
			cin >> event;
			if(event == "HIT")
			{
				data <<= 1;
				data |= 0x01;
				if(data & 0x08)
				{
					data &= ~0x08;
					score++;
				}
			}
			else if(event == "HOMERUN")
			{
				for(int i = 0;i < 3;i++)
				{
					if(data & (0x01 << i)) score++;
				}
				score++;
				data = 0;
			}
			else if(event == "OUT")
			{
				out++;
				if(out >= 3) break;
			}
			outputAsBinary(data);
		}
		cout << score << endl;
	}
	return 0;
}

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

using namespace std;

class Inning{
private:
  int out;
  int runnner;
  int point;
  int inningN;
public:
  Inning();//コンストラクタ
  void newInning();
  int getInningN(){return inningN;}
  int getPoint(){return point;}
  void doOut(){
    out ++;
    if(out == 3){
      newInning();
    }
  }
  void doHit();
  void doHomerun();
};

void Inning::doHit(){
  if(runnner < 3){
    runnner ++;
  }
  else{
    point ++;
  }
}
void Inning::newInning(){
  out = 0;
  runnner = 0;
  inningN ++;
  cout << point << endl;
}

void Inning::doHomerun(){
  point += runnner + 1;
  runnner = 0;
}


//コンストラクタ
Inning::Inning(){
  out = 0;
  runnner = 0;
  point = 0;
  inningN = 0;
}

int main(){
  int N;
  char *str;
  cin >> N;
  Inning inning;

  while(1){
    if(inning.getInningN() == N){
      break;
    }
    cin >> str;
    if(!strcmp(str, "OUT")){
      inning.doOut();
    }
    if(!strcmp(str, "HIT")){
      inning.doHit();
    }
    if(!strcmp(str, "HOMERUN")){
      inning.doHomerun();
    }
  }

  return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()

#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,a,b) for(int i=(a); i<(b); i++)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int IMAX=((1<<30)-1)*2+1;
const double EPS=1e-10;
//int mod=1000000007;

string s[3]={"HIT","HOMERUN","OUT"};


int main(){
	int n;
	cin>>n;
	rep(i,n){
		string t;
		int score=0,out=0;
		bool first=false,second=false,third=false;
		while(1){
			cin>>t;
			if(t==s[0]){
				if(third){
					score++;
					third=false;
				}
				if(second){
					third=true;
					second=false;
				}
				if(first){
					second=true;
				}
				first=true;
			}
			if(t==s[1]){
				score++;
				if(first){
					first=false;
					score++;
				}
				if(second){
					second=false;
					score++;
				}
				if(third){
					third=false;
					score++;
				}
			}
			if(t==s[2]){
				out++;
				if(out==3){
					cout<<score<<endl;
					break;
				}
			}
		}
	}
}