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<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;
    int ans=0;
    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==home.s){
            ans+=run.count+1;
            run.count=0;
        }
        if(temp==hit.s){
            run.count++;
            if(run.count>3){ans++; run.count-=1;}
        }
    if(temp==out.s){
        out.count++;
        if(out.count%3==0){cout<<ans<<endl;ans=0;run.count=0;}
        if(out.count==(n*3))return 0;
    }
    }
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>

#include<vector>

#define INF 999999
using namespace std;
int main(){
    int N;
    cin>>N;
    while(N--){
        int score=0,hitcnt=0;
        string sum;
        for(int out=0;out!=3;){
            cin>>sum;
            if(sum[0]=='O')out++;
            else if(sum[0]=='H'&&sum[1]=='I'){
                if(hitcnt==3)score++;
                else hitcnt++;
            }
            else{
                score+=hitcnt+1;
                hitcnt=0;
            }
        }
        cout<<score<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
int main(void){
    int n; //データセット数
    cin >> n;
        
    for(int i = 1; i <= n; i++){
        int countout = 0; //OUTの発生回数
        int counthit = 0; //HITの発生回数
        int score = 0; //イニングの得点

        while(countout != 3){
            string state;
            cin >> state;
            if(state == "OUT") countout++;
            else if(state == "HIT"){
                counthit++;
                if(counthit == 4){
                    score++;
                    counthit--;
                }
            }    
            else if(state == "HOMERUN"){
                score += counthit + 1;
                counthit = 0;
            }
        } 
        cout << score << endl;     
    }
}

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

class Baseball{
private:
	int runner; // 0~3: the number of runner
	int out_count; //0~2: out count
	int point;

public:
	Baseball(){
		runner = 0;
		out_count = 0;
		point = 0;
	}

	int judge(std::string event){
		if(event == "HIT"){
			return single_hit();
		}else if(event == "HOMERUN"){
			return home_run();
		}else{
			return out();
		}
	}

	void display(){
		std::cout << point << std::endl;
	}

	int single_hit(){
		(runner == 3) ? ++point : ++runner;
		return 1;
	}

	int home_run(){
		point = point + runner + 1;
		runner = 0;
		return 1;
	}

	int out(){
		if(out_count == 2){
			display();
			return 0;
		}else{
			++out_count;
			return 1;
		}
	}
};

int main(){
	int n; // the number of datasets
	std::cin >> n;

	for(int i = 0; i < n; ++i){
		Baseball inning;
		std::string eve;
		std::cin >> eve;
		while(inning.judge(eve) == 1){
			std::cin >> eve;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<cstring>
using namespace std;
int main()
{
	int base,i,j,n,o,point;
	char state[8];
	cin >> n;
	for(i=0;i<n;i++)
	{
		o=base=point=0;
		while(o<3)
		{
			cin >> state;
			if (strcmp(state, "HIT") == 0)
			{
					if(base == 3)
						point++;
					else
						base++;
			}
			else if (strcmp(state, "HOMERUN") == 0)
			{
					base++;
					point+= base;
					base =0;
			}
			else if (strcmp(state, "OUT") == 0)
					o++;
		}
		cout << point << endl;
	}
	return 0;
}

C++: #include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int main(){
	int n;
	cin>>n;
	rep(loop,n){
		int rui[5]={};
		string s;
		int o=0;
		int p=0;
		while(cin>>s){
			if(s=="HIT"){
				if(rui[3]==1)p++;
				rui[3]=rui[2];
				rui[2]=rui[1];
				rui[1]=1;
			}
			if(s=="OUT"){
				o++;
				if(o>=3)break;
			}
			if(s=="HOMERUN"){
				p+=1+rui[3]+rui[2]+rui[1];
				rui[3]=0;
				rui[2]=0;
				rui[1]=0;
			}
		}
		cout<<p<<endl;
	}
}

C++: #include <iostream>

class Baseball{
private:
	u_int score,out,runner,inning;
public:
    Baseball();
    ~Baseball()=default;
    void checkEvent(std::string event);
    void hit();
    void homerun();
    void countOut();
    u_int getInning();
};

Baseball::Baseball(){
	score=0,out=0,runner=0,inning=0;
}

void Baseball::checkEvent(std::string event){
    if(event=="HIT"){
        this->hit();
    }
    else if(event=="OUT"){
        this->countOut();
    }
    else if(event=="HOMERUN"){
        this->homerun();
    }
}

void Baseball::hit(){
	runner<3?++runner:++score;
}
	
void Baseball::countOut(){
	if(out<2){
		++out;
	}
	else{
	std::cout << score << std::endl;
	runner=0,out=0,score=0;++inning;
	}
}
	
void Baseball::homerun(){
	score+=runner+1;
	runner=0;
}	

u_int Baseball::getInning(){
	return inning;
}

int main() {
	Baseball game;
	int num;
	std::cin >> num;
	while(game.getInning()<num){
		std::string event;
		std::cin >> event;
		game.checkEvent(event);
	}
	return 0;
}

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

using namespace std;


int main(){
  int n,AUTO,total,home;
  string op;

  scanf("%d",&n);
  for(int i=0;i<n;i++){
    AUTO=0;
    total=0;
    home=0;
    while(true){
      if(AUTO == 3)break;
      cin >> op;
      if(op == "HIT"){
	home = (home<<1)+1;
	if(home>>3){
	  total++;
	  home = home & ~(1<<3);
	}
       
      }
      else if(op == "HOMERUN"){
	for(int i=0;i<3;i++){
	  if(home>>i & 1)total++;
	}
	total++;
	home=0;
      }
      else if(op == "OUT")AUTO++;
    }
    printf("%d\n",total);
  }
  return 0;
}

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;

void solve()
{
	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;
	return;
}

int main()
{
	cin >> n;
	REP(i, n)
	{
		solve();
	}

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

	return 0;
}