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

C++: #include<cstdio>
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int point=0;
        int base=0;
        int out=0;
        while(out!=3){
            char s[8];
            scanf(" %s",s);
            switch(s[1]){
                case 'I':
                    base++;
                    if(base==4){
                        point++;
                        base--;
                    }
                    break;
                case 'U':
                    out++;
                    break;
                case 'O':
                    point+=base+1;
                    base=0;
                    break;
            }
        }
        printf("%d\n",point);
    }
    return 0;
}